Quote:
Originally Posted by hitman050
Can you please explain (!flag)?
|
If your question is about operator
!
! is a unary operator - meaning takes only one operand and takes a boolean operand always (atleast in Java. I forgot about C++ and I forgot whether C++ has boolean as a datatype or does it use 0 and 1)
Ex: x is a boolean variable.
x = true;
cout>>x; // Will output true
cout >> !x; // Will output false
Now, don't ask us whats
unary and whats
boolean. If those are your doubts then you might want to log off and get back to Chapter 1 in your books.
If your question is about
(!flag), then the author meant
if(flag == false)
if(!flag) is just a short for
if(flag == false)
Again, depending on the programming language, you might have to replace false with 0 and true with 1 in above snippets.