1/9
These flashcards cover key definitions, declarations, and examples of arrays and multidimensional arrays from the lecture notes.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No study sessions yet.
What is an array in programming?
A collection of elements of the same data type, stored in contiguous memory locations and accessed using an index.
How do you declare an array?
Using the syntax: dataType arrayName[size];
What are the rules for declaring an array?
What is the initialization syntax for an array?
dataType arrayName[size] = {elements};
How many elements can the array int scores[5] hold?
It can hold 5 elements.
What is the value stored at index 2 in the array numbers[5] = {10, 20, 30, 40, 50}?
30.
What happens if you access numbers[5] in the numbers array?
It causes out-of-bounds access (undefined behavior).
What is a multidimensional array?
An array of arrays that stores data in more than one dimension, commonly a 2D array.
Provide an example of a 2D array declaration.
string letters[2][4] = { { 'A', 'B', 'C', 'D' }, { 'E', 'F', 'G', 'H' } };
How do you access an element in a multidimensional array?
Using the syntax: arrayName[row][column]. For example, letters[1][2] returns 'G'.