Observe the following code:
const int SIZE = 3;
int nums[SIZE] = {1, 2, 3};
for (int i = 0; i <= SIZE; i++) {
std::cout << nums[i];
}
What is wrong with this code?
A: You cannot use constants with array definitions.
B: The initialization list exceeds the size of the array.
C: Should be i = 1 because you need to start with the first array element.
D: Should be I < SIZE so that you don't access an array element that doesn't exist.
D: The last element of the array nums has index SIZE-1
Comments
Leave a comment