Class 13: Arrays and Pointers Flashcards

1
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Statically allocated arrays

A

Compiler generates code to allocate the space for the array elements at compile time. The space is allocated on the stack or the heap depending on the declaration statement. (File or block scope/ static or automatic class)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Dynamically allocate arrays

A

A c library function is called to request space for the array elements at runtime. This is after the program starts running. Need to declare a pointer to array we want space to reprint to hold the address of this block of memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What arrays are these
Int scores[6] = {19,17,18,16,15,20};
Int scores[] = {19,17,18,16,15,20}

A

Statically allocated arrays

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Arrays of static storage class will be initialized to ____

A

0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Arrays of ___ storage class are not initialized in any way unless specifically done so with code

A

Automatic

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Is there a library function for copying arrays in c?

A

NO

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Int scores[3] = {1,2,3};
Scores is equivalent o

A

&scores[0]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

In c, the name of the array itself is a _____ to the _____ element of the array

A

A constant pointer to the first element of the array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Because in arrays, pointer to the first element of an array is CONSTANT, it _____ be changed. You CANNOT assigne a different address to it

A

Cannot
Int scores[3] = {1,2,3};
Int scores2[2] = {4,5};
Int *scores_ptr;
Scores_ptr = scores2;
Scores = scores_ptr ——> INCORRECT

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

All array elements are stored in _____ memory locations

A

Contiguous

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is *(scores + 3) equivalent to?

A

Scores + 3
Scores + (3sizeof(int))
&scores[0] + (3
sizeof(int))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Opening a file

A

FILE *input_file;
Input_file = fopen(“lab2_datafile”,”r”);

Or
Char filename[256];
Scanf(“%s”,filename);
Input_file = fopen(filename,”r”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How to read front file

A

FILE *output_file;
Output_file = fopen(“lab2_output”, “w”);
Fscanf(file_name, “%f”, &float_val);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How to write to a file

A

Fprintf(file_name, …)

18
Q

How to close a file

A

Fclose(file_name)