Arrays Flashcards

1
Q

Define arrays

A

A method of grouping together mulitple values of the same type into a larger group (e.g. int)

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

Why use arrays?

A

Arrays are a group of values which can be selected by index.
-Stored in a contiguous part of the memory
-all values are the same type

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

What is a common problem with arrays?

A

When iterating past the end of the array, the memory is accessed wich can produce unpredictable results

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

How do we define a 2D array

A

int values[n][m]

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

How can memory be assigned dynamically

A

malloc - allocates memory and leaves it unitialised
calloc - sets to zero
realloc - new memory size for existing array

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

using arrays how do we find the maximum value

A

The maximum is assigned as the first value. (index 0)
The other elements are checked starting from index 1 `

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

Using arrays, how can an element be added in the middle?

A

Provided the array is declared large enough, values to the right of the new value are shifted

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

How do we pass an array through a function?

A

function(array , array size)

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