LearnFrenzy
Sign in Take a free test

C Loops · Predict the Output · Question 6

Two counters with the comma operator – output Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 6 Back to Exercise

What is the output of the following C program?

main.c
#include <stdio.h>

int main(void) {
    int i, j;
    for (i = 0, j = 10; i < j; i += 3, j -= 2) {
    }
    printf("%d %d\n", i, j);
    return 0;
}
  • A 6 6 Correct
  • B 9 4
  • C 3 8
  • D 6 8
Correct Answer: Option A

The pairs are (0, 10), (3, 8), then (6, 6), where i < j is false. Both updates happen together in each step.

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