Arrays Flashcards
Define arrays
A method of grouping together mulitple values of the same type into a larger group (e.g. int)
Why use arrays?
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
What is a common problem with arrays?
When iterating past the end of the array, the memory is accessed wich can produce unpredictable results
How do we define a 2D array
int values[n][m]
How can memory be assigned dynamically
malloc - allocates memory and leaves it unitialised
calloc - sets to zero
realloc - new memory size for existing array
using arrays how do we find the maximum value
The maximum is assigned as the first value. (index 0)
The other elements are checked starting from index 1 `
Using arrays, how can an element be added in the middle?
Provided the array is declared large enough, values to the right of the new value are shifted
How do we pass an array through a function?
function(array , array size)