Is it a child-play or a coding line?

What is the output of the following c++ program?

1
2
3
4
5
6
 void main()
 {
 int a;
 a=0?(5>3?32:(11>17?(6>9?34:84):64)):1;
 printf("%d",a);
 }

Assumptions

  • The stdio.h library is available for this program.


The answer is 1.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Ayesha Khurram
May 22, 2014

The operator used is assignment operator (=), not comparison operator (==). So a will be assigned a value of 0, which is false and the false part of ternary operator is 1 so a will then be assigned the value of 1.

exactly correct

Khan Sameer - 6 years, 9 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...