LearnFrenzy
Sign in Take a free test

C Loops · Predict the Output · Question 1

for loop with a semicolon after it – output Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 1 Back to Exercise

What is the output of the following C program?

main.c
#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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links