How this program behaves at execution..... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How this program behaves at execution.....

#define TRUE #define FALSE main() { #ifdef TRUE && FALSE printf ("true") ; #else printf("false"); #endif }

14th Apr 2020, 6:53 AM
Muralikrishnan
Muralikrishnan - avatar
2 Answers
+ 1
Here true and false Are predefined And in 1st case true && false will result in 0 which means Else will be executed, it will print false
14th Apr 2020, 7:04 AM
Raj Kalash Tiwari
Raj Kalash Tiwari - avatar
0
It seems like this code prints true despite being syntactically incorrect. #ifdef just checks whether TRUE is somehow defined, which it is, and the rest with the && FALSE doesn't matter. Or in other words the compiler ignores the incorrect instructions "&&" and "FALSE" but it could throw an error as well. And you also need to write int main, not just main :)
14th Apr 2020, 7:04 AM
Aaron Eberhardt
Aaron Eberhardt - avatar