C Programming :: Declarations and Initializations - Discussion
13 / 54
#include <stdio.h>
void main()
{
printf("%d",10?0?5:1:12);
}
#include <stdio.h>
void main()
{
printf("%d",10?0?5:1:12);
}
A10
B0
C12
D1
Show Explanation
(Test condition) ? value_if_true : value_if_false
Line no. 3 i.e, 10?(0?5:1):12 simply means if 10 is true then return (0?5:1) else return 12.
Again, (0?5:1) simply means if 0 is true then return 5 else return 1.
So here, 10 is true so the result is (0?5:1), and here 0 is false, which gives 1 as the output, hence the correct option is option D.
Asked In ::
In C, the syntax for ternary operators is:
(Test condition) ? value_if_true : value_if_false
Line no. 3 i.e, 10?(0?5:1):12 simply means if 10 is true then return (0?5:1) else return 12.
Again, (0?5:1) simply means if 0 is true then return 5 else return 1.
So here, 10 is true so the result is (0?5:1), and here 0 is false, which gives 1 as the output, hence the correct option is option D.
Read Full Answer
Report Error
Please Login First Click Here
The Answer should be 1, Because the will return the value of condition and printf will print the output .
10?0?5:1:12 (here 10 is true)->0?5:1(Here 0 is false)-> 1 is output.
Read Full Answer
Report Error
Please Login First Click Here