LearnFrenzy
Sign in Take a free test

Operators and Expressions · Predict the Output · Question 5

x = (1, 2, 3) and y = 4, 5 – output Answer, explanation & discussion

  • Output
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 5 Back to Exercise

What is the output of the following C program?

main.c
#include <stdio.h>

int main(void) {
    int x = (1, 2, 3);
    int y;
    y = 4, 5;
    printf("%d %d\n", x, y);
    return 0;
}
  • A 3 4 Correct
  • B 1 5
  • C 3 5
  • D 1 4
Correct Answer: Option A

With brackets, the comma operator yields its last operand: x = 3. Without them, = binds tighter than ,, so y = 4, 5 is (y = 4), 5.

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