Question discussion

What is the output of the following C program?#include int main() { int a = 0, b = 5, c; c = (a++ && b++) || (++b > 5); printf("%d %d %d",…

1574Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following C program?

#include <stdio.h>
int main() {
    int a = 0, b = 5, c;
    c = (a++ && b++) || (++b > 5);
    printf("%d %d %d", a, b, c);
    return 0;
}
  • A1 7 1
  • B1 6 1
  • C0 6 1
  • D1 5 0
Correct answer: B

Explanation

a++ yields 0 (and a becomes 1), so && short-circuits and b++ is not evaluated; ++b makes b = 6 and (6 > 5) is true, so c = 1.

Discussion 0

Nobody has replied yet. Start the discussion!