C++ Tutorials

C++ Tutorials

C++ has a special shorthand that simplifies coding of certain type of assignment.

For Example

a = a + 2;

can be written as :

a += 2;

Shorthand works for attribute binary operators in C++.

Syntax :

variable operator = variable / constant / expression

Operators are listed below :

Operators Example Meaning
+= a+=2 a=a+2
-= a-=2 a=a-2
*= a*=2 a=a*2
/= a/=2 a=a/2
%= a%=2 a=a%2
&&= a&&=2 a=a&&2
||= a||=2 a=a||2