2 Operators
2 Operators
sizeof() Returns the size of a variable. sizeof(a), where a is integer, will return 4.
• C++ has two operators to change the value of the operand by 1. These
operators are:
Increment operator (++): it increments the value of operand by 1
Decrement operator (--): it decreases the value of the operand by 1
Pre-increment
• A pre-increment operator is used to increment the value of a variable before
using it in a expression that is first value is incremented and then used
inside the expression.
• Syntax: a = ++x;
• Example: if x = 10;
a = ++x;
then a = 11
Because the value of ‘x’ is modified before assigning it to ‘a’
Post-increment
• A post increment operator is used to increment the value of the variable
after executing expression completely in which post increment is used.
• Syntax: a = x++;
• Example: if x = 10;
a = x++;
then a = 10
Because the value of ‘x’ is modified after assigning it to ‘a’
Pre decrement and Post decrement
• Pre decrement and post decrement works same as the pre increment and
post increment respectively.
• The only difference is that it is used to decrease the value of the operand by
1.