Archived

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

Teric

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 this post


Link to post
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
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 this post


Link to post
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 this post


Link to post
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 */
/*=========================================*/

Share this post


Link to post
Share on other sites