the code is:
i = 2; j = 1
printf("%d", !!i + !j);
(the answer comes out to be 1... i don't understand why [and i don't know what the "!!" means (only the "!")...
Printable View
the code is:
i = 2; j = 1
printf("%d", !!i + !j);
(the answer comes out to be 1... i don't understand why [and i don't know what the "!!" means (only the "!")...
What your code is saying is not(not)i + not j, which means i is a true statement, regardless of the integer you assigned and j is a false statement. So, in effect, your code is saying true + false. That will equal 1. If you change it to !i + !j, it will equal 0.
!! means not not.
x = 1;
if( x ) //true
if( !x ) //false
if( !!x ) //true
Recall that any non-zero value equates to true in a true/false test. Thus, not one means zero (or false), so not zero means true.
Quzah.
Hmmm...two negatives equal a positive thing right...algebra strikes back. Then again it could mean other things but I dont' know how big Simpsons fans you people are so nevermind ;)