Answer to Question #325100 in C++ for nickname

Question #325100

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.


1
Expert's answer
2022-04-09T17:55:36-0400

D: The last element of the array nums has index SIZE-1


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS