2

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.

Vishal Anand
  • 474
  • 1
  • 4
  • 17
  • 1
    Just because an IDE highlights something doesn't mean that it exists. – Matti Virkkunen Oct 09 '13 at 01:57
  • @MattiVirkkunen I concur, but in this case it was the "Gedit", so I was curious and hence the question. – Vishal Anand Oct 09 '13 at 01:58
  • @Troy I am not sure if it is indeed a duplicate, as the question was not related in its entirety; the solution was nevertheless more general, and hence I could not locate it in the first search on the web. – Vishal Anand Oct 09 '13 at 02:03

2 Answers2

4

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

enter image description here

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  ^=
Yu Hao
  • 119,891
  • 44
  • 235
  • 294
1

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.

Community
  • 1
  • 1
tckmn
  • 57,719
  • 27
  • 114
  • 156