What is the function of and() in C++ and its syntax?
P.S. I happened to write out and() as a function and the C++ text editor highlighted it. Even after much searching I could not find its function or the syntax.
What is the function of and() in C++ and its syntax?
P.S. I happened to write out and() as a function and the C++ text editor highlighted it. Even after much searching I could not find its function or the syntax.
There is no and
function in C++, it's a reserved identifier, the same as the logical operator &&
.
C++11(ISO/IEC 14882:2011) §2.5 Alternative tokens
In C, there's no and
keyword, but if you include the header iso646.h
, and
is the same as &&
as well.
C11(ISO/IEC 9899:201x) §7.9 Alternative spellings
The header
<iso646.h>
defines the following eleven macros (on the left) that expand to the corresponding tokens (on the right):and && and_eq &= bitand & bitor | compl ~ not ! not_eq != or || or_eq |= xor ^ xor_eq ^=
and
is not a function; it is an operator. It means the same thing as &&
. For example,
x && y
and
x and y
mean the same thing.
If you try to use it as a function, it will give you an error.
See this answer for more information on and
, or
, etc.