Question 4
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
for (int i = 0; i < 4; i++) {
const int sq = i * i;
printf("%d ", sq);
}
printf("\n");
return 0;
}
- A 0 1 4 9 Correct
- B 0 0 0 0
- C Compilation error: sq is assigned 4 times
- D 0 1 2 3
Correct Answer: Option A
Each pass creates a new sq and initialises it once – that is not an assignment to a const. const locals are perfectly normal inside loops.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!