+ 4

Can someone explain this code output

If(true or "True") { Cout<<!"True"; } Else { Cout<<!true; }

24th Apr 2020, 4:33 PM
The CodeGeek
The CodeGeek - avatar
4 Réponses
+ 7
Tnx swim I understood it clearly completed solved my misunderstanding tnx ... I really didn't know about boolalpha tnx
24th Apr 2020, 4:59 PM
The CodeGeek
The CodeGeek - avatar
+ 6
Apart from auto capitalize feature of first letters which leads the code to an invalid state, it really is just a simple comparison and boolean operation. if(true or "True") Here "True" is not even counted for because the LHS operand is true anyways. So execution flow switches to the true block. And prints out the result of logical NOT operator given a string literal ("True"). {Uncertain point} When a literal string is treated as boolean like that, it seems the address of the literal is being used as operand for the logical NOT operator (*probably*). I came to this assumption because !"" (Empty string literal) still yields 0 (false). The last paragraph above is speculative, I'm all ears for corection. That was how I see it, and I could surely be wrong.
24th Apr 2020, 4:52 PM
Ipang
+ 3
Ipang "true" and"True" both will output same thing? I.e 1 isn't it?
24th Apr 2020, 5:04 PM
The CodeGeek
The CodeGeek - avatar