5 - Arrays Flashcards

1
Q

What is an array?

A

An array behaves like a list of variables with a uniform naming mechanism that can be declared in a single line of simple code.

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

Declare an array, score, which consists of five variables type int.

A

int score [5];

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

What is the name of the number in brackets in the array?

score [5];

A

Index

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

Define: size of array.

A

The number of indexed variables in the array is called the declared size of the array, or sometimes simply the size of the array.

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

What is the base type of the array?

A

The base type refers to the type of variables stored in the array. All indexed variables in one array are of the same type.

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

What is a common loop used with arrays?

A

The for-loop is ideally suited to array manipulations.

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

The indexes of an array always starts with…

A

0

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

The indexes of an array always ends with …

A

size - 1

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

Can variables be used to declare array size?

A

You may be tempted to use a variable for the array size., but not all compilers will allow this. For the sake of portability you should not do so. Use constants, not variables. Or use dynamic arrays or declare an array size that is of the largest size the program could possibly need.

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

What is the most common programming error made when using arrays?

A

Attempting to reference a nonexistent array index.

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

What happens if you reference a nonexistent array index?

A

Unfortunately, most compilers will allow you to do this. As long as the program has the permission to read or write from that memory location, it will do so if given the instructions to.

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

The most common programming error made when using arrays is attempting to reference a nonexistent array index. When does this usually happen?

A

At the first or last iteration of a loop that processes the array.

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

How do you initialize the array children of size three along with its declaration?

A

int children [3] = {2, 12, 1}

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

int b[] = {5, 12, 11}

Is this legal?

A

Yes. The array is now set to size 3.

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

We have an array called a.

void showTheWorld ( const int a [], int sizeOfa)

Why const?

A

In a complicated function you might write code that inadvertently changes one or more of the values stored in the array even though the array should not be changed at all. It is a good idea to use const.

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

Can you return an array?

A

No. You have to return a pointer to an array.

17
Q

How do you declare an array with more than one index?

A

char page [30] [100]

18
Q

The two-dimensional array page is actually an array of arrays.

char page [30] [100]

What does it mean to be an array of arrays?

A

The array page shown is actually a one-dimensional array of size 30, whose base type is a one-dimensional array of characters of size 100.