Aspire's Library

A Place for Latest Exam wise Questions, Videos, Previous Year Papers,
Study Stuff for MCA Examinations - NIMCET

Previous Year Question (PYQs)



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) $$


Online Test Series,
Information About Examination,
Syllabus, Notification
and More.

Click Here to
View More


Online Test Series,
Information About Examination,
Syllabus, Notification
and More.

Click Here to
View More

Ask Your Question or Put Your Review.

loading...