Arrays Flashcards
older and more basic than vector is the
arrays
blank are sequences of objects of the same type
arrays
objects in arrays are allocated blank in memory
sequentially
items can be accessed with [] operator
no .at()
once allocated the blank of an array cannot be changed
the size of the array cannot be changed
True or false:
the size of the array itself is not stored with the array itself
True
size of the array itself is not stored with the array itself
to declare an array, specify the type and size
int numbers[5];
bool flags[10];
the blank precedes the variable name
the blank is specified in the [ ] after it
the type precedes the variable name
the size is specified in the [ ] after it
arrays can be given blank
arrays can be given initial values
if not given blank, the items in the array are undefined random memory garbage until assigned
initial values
to write a function that accepts an array as an argument, declare it like a normal array, but omit the length of the array from the [ ], and supply it as another argument: int sum(int numbers{ }, int length)
it’s important to supply the length because otherwise the function can’t figure out how large the array is
you can declare the array argument to be a blank
pointer int sum(Int* numbers, int length)