+ 1

Why output is 'Try Again' ?

int main() { #if !SOLO printf("Try Again"); #else printf("Sololearn"); #endif return 0; return 0; } Somehow string '!SOLO' is getting converted to a non-zero value. Can someone explain how ?

22nd May 2020, 6:32 AM
Peter Parker
Peter Parker - avatar
3 Antworten
+ 3
Is this all the code? Is SOLO defined? If not then SOLO is 0 and it is saying !0 which is 1. #define SOLO 1
22nd May 2020, 7:41 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
Ya, that's pretty much what I said. Lol Add the #define line from my previous post before main (or at least before the #if) and it will work as expected.
22nd May 2020, 8:36 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
ChaoticDawg This is the whole code and it runs without any error. My guess is if SOLO is not defined (as in this case) it will be treated as 0.
22nd May 2020, 8:25 AM
Peter Parker
Peter Parker - avatar