I've noticed other people using "and" in place of &&, I'm wondering what the difference is. I can see the advantages of the former and I'd like to move to it, but I can't seem to find neither hide nor hare of it in the cplusplus tuts.
int a = 5, b = 5;
if( a == 5 && b == 5 ) return 1;
if( a == 2 and b == 2 ) return 2;
if( a == 5 or b ==3 ) return 3;
//All are apparently valid though I'm not sure what the differences are.
return 0;
Those are the and/or's I mean. I get the logical operators already, but it's just the syntax I'm unfamiliar with. I'm assuming that there are also others, perhaps 'not' instead of '!' ... >.>;
When I first started learning c++, we were discouraged from using the 'and' or 'or' instead were told to use '&&' and '||'. It was only recently that I found out you can actually type 'and' without getting an error
The rationale for it being discouraged is because it's not widely accepted by developers as the way to write code. But you would need to consult the coding standard your organisation uses. I have yet to work in an organisation that would accept "and" over "&&"
The ciso646 defines macros, but the note says:
"In C++, reserved words exist and are treated as aliases of their respective operator."
C had logical operators and C++ did inherit them. Someone thought that it would be neat to be able to write (A and B) instead of (A && B). Macros and preprocessor make that possible. Compiler with extensions makes that possible. Standard that adds keywords makes that possible.
Being possible may make someone happy, but it does not mean that everybody will change their habits (and revise tutorials), particularly when && has been fine the whole time and still is.