Topic 8 - Arrays Flashcards

1
Q

Is it legal or illegal for an initializer to be completely empty?

A

Illegal. must have at least a single 0

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

What is the notation for multidimensional arrays?

A

M[i][j]

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

How does c store arrays?

A

in “row-wise order” with row 0 first, then row 1 and so forth:
row1-row2-row3

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

What is the syntax for creating an initializer for 2-dimensional array?

A

int m[5][9] = {{1, 1, 1, 1, 1, 0, 1, 1, 1},
{0, 1, 0, 1, 0, 1, 0, 1, 0},
{0, 1, 0, 1, 1, 0, 0, 1, 0},
{1, 1, 0, 1, 0, 0, 0, 1, 0},
{1, 1, 0, 1, 0, 0, 1, 1, 1}};

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

Can you omit the inner brackets in 2-dimensional array initialization?

A

Yes. We can even omit the inner braces:
int m[5][9] = {1, 1, 1, 1, 1, 0, 1, 1, 1,
0, 1, 0, 1, 0, 1, 0, 1, 0,
0, 1, 0, 1, 1, 0, 0, 1, 0,
1, 1, 0, 1, 0, 0, 0, 1, 0,
1, 1, 0, 1, 0, 0, 1, 1, 1};
Once the compiler has seen enough values to fill one row, it begins filling the next
• Omittingtheinnerbracescanberisky,sincemissing an element will affect the rest of the initializer

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

Syntax for designated initializers work with multidimensional arrays:

A

double identity[2][2] = {[0][0] = 1.0, [1][1] = 1.0};

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

How do you make an array constant?

A

An array can be made “constant” by starting its declaration
with the word const:
const unsigned char hex_chars[] = {‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’};

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

When is the length of a Variable-Length array computed?

A

When the program is executed.

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

Syntax for Variable-Length arrays? Doe it have to be specified by a single variable?

A
No.
int n;
int a[n];
int a[3*i+5];
int b[j+k];
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the 2 restrictions on VLAs:

A

1) can not have an initializer

2) can not have static storage duration (discussed in ch 18)

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