Q: What is an array?
A: An array is an aggregate data type that lets us access many variables of the same type through a single identifier.
Q: Which index would you use to access the 2nd variable in an array?
A: The second element has index 1. Ie…“array[1]”.
Q: What can you say about the size of an array?
A: The size of an array can be worked with in many ways in C++.
A fixed array (also called a fixed length array or fixed size array) is an array where the length is known at compile time.
Each of the variables in an array is called an element. Elements do not have their own unique names. Instead, to access individual elements of an array, we use the array name, along with the subscript operator ([]), and a parameter called a subscript (or index) that tells the compiler which element we want. This process is called subscripting or indexing the array. Array subscripts must always be an integral type. This includes char, short, int, long, long long, etc… and strangely enough, bool (where false gives an index of 0 and true gives an index of 1). An array subscript can be a literal value, a variable (constant or non-constant), or an expression that evaluates to an integral type.Fixed array declarations the length of the array (between the square brackets) must be a compile-time constant. This is because the length of a fixed array must be known at compile time.Because fixed arrays have memory allocated at compile time, that introduces two limitations:
Fixed arrays cannot have a length based on either user input or some other value calculated at runtime.
Fixed arrays have a fixed length that can not be changed.
In many cases, these limitations are problematic. Fortunately, C++ supports a second kind of array known as a dynamic array. The length of a dynamic array can be set at runtime, and their length can be changed. However, dynamic arrays are a little more complicated to instantiate.
/////////////////////////////////////////////////////
Q: How can you initialize an array?
A: C++ provides a more convenient way to initialize entire arrays via use of an initializer list.
Q: How can you get the size of an array in bytes?
A: when we’re talking about the number of elements in the array, and “size” when we’re referring to how large something is in bytes.
Q: How can you use the function size of in order to calculate the number of elements in an array?
A: The sizeof operator can be used on arrays, and it will return the total size of the array
Q: What happens when you try to write outside the bounds of the array?
A: you will get undefined behavior – For example, this could overwrite the value of another variable, or cause your program to crash.