Question 1
Back to Exercise
What is the output of the following C program?
#include <stdio.h>
int main(void) {
int i;
for (i = 0; i < 5; i++);
printf("%d\n", i);
return 0;
}
- A 5 Correct
- B 01234
- C 4
- D 0
Correct Answer: Option A
The semicolon right after the header is the loop body – an empty statement. The loop counts i up to 5, and only then does printf run, once. Compilers warn about this classic slip.
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!