Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between "and" and "&&" in c++

Recently I found a code where is used the keyword and which working like &&. So are they both the same or is there any specific condition to use it?

like image 718
S_coderX451 Avatar asked Jan 24 '23 07:01

S_coderX451


2 Answers

The C++ standard permits the token && to be used interchangeably with the token and.

Not all compilers implement this correctly (some don't bother at all; others require the inclusion of a special header). As such, code using and can be considered idiosyncratic.

The fact that the equivalence is at the token, rather than the operator, level means that since C++11 (where the language acquired the rvalue reference notation), you can arrange things (without recourse to the preprocessor) such that the statement

int and _int(string and vector);

is a valid function prototype. (It's eqivalent to int&& _int(string&& vector).)

like image 193
Bathsheba Avatar answered Jan 26 '23 21:01

Bathsheba


As can be seen here, they're the same thing.

like image 43
Silidrone Avatar answered Jan 26 '23 20:01

Silidrone