+ 4
Can someone explain this code output
If(true or "True") { Cout<<!"True"; } Else { Cout<<!true; }
4 Answers
+ 7
Tnx swim I understood it clearly completed solved my misunderstanding tnx ... I really didn't know about boolalpha tnx
+ 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.
+ 3
Ipang "true" and"True" both will output same thing? I.e 1 isn't it?