How !x operator works?! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How !x operator works?!

29th Dec 2016, 4:39 PM
N.H
N.H - avatar
2 Answers
+ 6
Allow me to do a little correction to your query: From what I perceive, 'x' may be a boolean variable which holds value of either true, or false, The operator in question here is the ! operator. The ! operator is the NOT operator, which is used to return the negation of the truth value of whatever comes after it. e.g. bool x = true; cout << x << endl; cout << !x << endl; // outputs 1 and 0.
29th Dec 2016, 5:23 PM
Hatsy Rei
Hatsy Rei - avatar
+ 2
! is a unary operator that complements a binary digit or a boolean. When x is an integer, it is converted to 1 (true) if x is nonzero otherwise it is converted to 0 (false). Now you apply the ! operator. !true == false and ! false==true
29th Dec 2016, 5:35 PM
Suvaditya
Suvaditya - avatar