简体   繁体   中英

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?

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) .)

这里可以看出,它们是同一回事。

No difference. and is just an alternative name for && .

See https://en.cppreference.com/w/cpp/keyword/and .

There is nothing different in and and &&

The and operator is an alternative representation of the && operator (binary or logical AND).

you can see the complete article here -

http://docwiki.embarcadero.com/RADStudio/Sydney/en/And

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

The main difference is that and doesn't use the character &.

Otherwise, there is no difference.

is there any specific condition to use it?

Along with other alternative tokens such as the digraphs, it exists in order to allow writing programs on exotic systems with character encoding (such as BCD or ISO 646) that don't have the special symbols such as &.

Unless you're writing on such system where it's necessary to use alternative tokens, you conventionally shouldn't be using them.

他们和运算符 si 他们是 && 的名字

and运算符是&&运算符的替代。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM