Question discussion

What is the output of the following C program?#include int main() { int x = 0; if (x = 5) printf("A"); else printf("B"); printf("%d", x); r…

2524Medium DSSSB TGT Computer Science 0 replies 1 views
0

What is the output of the following C program?

#include <stdio.h>
int main() {
    int x = 0;
    if (x = 5)
        printf("A");
    else
        printf("B");
    printf("%d", x);
    return 0;
}
  • AA5
  • BB0
  • CA0
  • DB5
Correct answer: A

Explanation

The condition is the assignment x = 5, which stores 5 in x and has the non-zero (true) value 5, so A is printed, followed by the new value 5 of x.

Discussion 0

Nobody has replied yet. Start the discussion!