#### Archived

This topic is now archived and is closed to further replies.

# Strange operator

## Recommended Posts

I was reading some code on a website, and I came across a strange operator: int a=!! (b+c) Has anyone seen this !! operator before? Is it simply a double ''not'' operator? How does it work? Let''s assume that b is 5 and c is 11, what would a be in the expression above? Thanks in advance!

##### Share on other sites
Hmmm...never seen that before. If it is just a double negation, they would just cancel each other out.

My best guess, it''s a typo.

/*=========================================*/
/* Chem0sh */
/* Lead Software Engineer & Tech Support */
/* http://www.eFaces.biz */
/*=========================================*/

##### Share on other sites
It''s a double negation, except it evaluates to true or false. So for 5 and 6, the result will be true or 1 if converted to an integer.

##### Share on other sites
Maybe transform the result in 0 or 1:

if C = 11 and B = 5 then

C + B = 16 -> not zero
!(C+B) = 0
!(!(C_B)) = 1

##### Share on other sites
Thanks for the quick responses!

##### Share on other sites
Another way to do the same thing (helps to understand what''s happening):

int a = (b+c)?1:0;

So if b+c is 0, "a" gets 0, otherwise "a" gets set to 1.

##### Share on other sites
Hmm...I think that''s the first time I''ve actually seen the ternary operator actually make something easier to understand.

/*=========================================*/
/* Chem0sh */
/* Lead Software Engineer & Tech Support */
/* http://www.eFaces.biz */
/*=========================================*/

• ### Forum Statistics

• Total Topics
628333
• Total Posts
2982130

• 24
• 9
• 9
• 13
• 11