Aspire Faculty ID #12759 · Topic: JECA MCA 2023 · Just now
JECA MCA 2023

What is the output?

#include <stdio.h>
void main(){
  int x = -1, y = 1, z = 0;
  if(x && y++ && z)
    ++x, y++, --z;
  printf("%d, %d, %d", x++, y++, z++);
}

Solution

Explanation: In the condition x && y++ && z, since z = 0, the logical AND short-circuits and the body of the if is not executed. However, y++ is evaluated before the short-circuit, so y becomes 2. Values before printing: $$ x = -1,\ y = 2,\ z = 0 $$ So the program prints: $$ (-1,\ 2,\ 0) $$

Previous 10 Questions — JECA MCA 2023

Nearest first

Next 10 Questions — JECA MCA 2023

Ascending by ID
Ask Your Question or Put Your Review.

loading...