what would be the output of this code and how?? | Sololearn: Learn to code for FREE!
0

what would be the output of this code and how??

#include <stdio.h> int main() {int exp=1?0:2?3:4; printf("%d",exp); return 0;}

2nd Jan 2022, 6:23 AM
Nariman Tajari
Nariman Tajari - avatar
3 Answers
+ 3
You know ternary operator? a short form of if...else conditionals ... <exp> = ( 1 ? 0 : ( 2 ? 3 : 4 ) ) Does this look clearer?
2nd Jan 2022, 6:38 AM
Ipang
+ 3
Well you know a non-zero number is considered truthy in C/C++ right? So that part was like "is 2 a truthy value? if so then give back 3, else give back 4"
2nd Jan 2022, 6:56 AM
Ipang
+ 1
yes Ipang but i donno how i should solve this part (2 ? 3 : 4)
2nd Jan 2022, 6:49 AM
Nariman Tajari
Nariman Tajari - avatar