Question 5
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
int i = 100;
for (int i = 0; i < 3; i++) {
}
printf("%d\n", i);
return 0;
}
- A 100 Correct
- B 3
- C 2
- D Compilation error
Correct Answer: Option A
The loop declares a new i that exists only inside the loop and shadows the outer one. The outer i is never touched and is still 100.
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!