1. What is an array?
2. Which index would you use to access the 2nd variable in an array?
3. What can you say about the size of an array?
A1) An array is an aggregate data type which allows us to execute many variables of the same type in a single identifier.
A2) I would use index (subscript) [1] to access the second variable, because in C++ arrays start counting from (0)
A3) The size of an array is always a fixed number and known at time of compiling.
- How can you initialize an array?
- How can you get the size of an array in bytes?
- How can you use the function sizeof in order to calculate the number of elements in an array?
- What happens when you try to write outside the bounds of the array?
A1) You can initialise an array through what is called an ‘Initialiser list’. This is done by inserting the values within curly brackets after the subscript (Index)
A2) You can get the size of an array in bytes by using the sizeof() operator.
A3) We can do this by dividing the size of the entire array by the of the size of the array element.
A4) Writing outside the bounds of an array will result in undefined behaviour, possibly overwriting the value of other variables or causing the program to crash.