Di Posting Oleh : Simple Learning
Kategori : C++ Increment and decrement operators postfix postfix decremet operator postfix increment operator prefix prefix decrement operator prefix increment operator
Increment Operators
Post-fix increment operator
Example:
int a=100,b;
b=a++;
Output
a: 101
b: 100
Decrement Operator
There are two types of decrement operator
Postfix Decrement Operator
Example:
int a=100,b;
b=a--;
Output
a: 99
b: 100
Postfix Decrement Operator
Example:
int a=100,b;
b=--a;
Output
a: 99
b: 99
- Symbol ++
- It is unary operator.
- It is used to increase the value of variable by 1.
- It can be used before and after the variable.
- It can be used with constants and expression .only the variables van is incremented.
- Post-fix increment operator.
- Pre-fix increment operator.
Post-fix increment operator
- When ++ is follows its operand (variable), it is called post-fix increment operator.
- Post-fix increase the value of variable after the execution of the statement it first uses the current value of variable in the statement and after the completion of the statement it increases the value by one.
Example:
int a=100,b;
b=a++;
Output
a: 101
b: 100
Decrement Operator
- Symbol - -
- It is unary operator.
- It is use to decrease the value of the variable by one.
- It can be used before or after the variable name.
- It cannot be used with constants and expressions. Only the variables can be decremented.
There are two types of decrement operator
- Postfix Decrement Operator
- Prefix Decrement Operator
Postfix Decrement Operator
- When - -is follows its operand, it is called postfix decrement operator.
- In postfix decrement, - - decrease the value of variable after the execution of the statement
- i.e . It first uses the current value of the variable in the statement and after the completion of the statement it decreases the value by one.
Example:
int a=100,b;
b=a--;
Output
a: 99
b: 100
Postfix Decrement Operator
- When - - is precedes its operand, it is called prefix decrement, - -decreases the value of the variable before the execution of the statement i.e. it first decreases the current value of the variable by one and then new value is used in the statement.
Example:
int a=100,b;
b=--a;
Output
a: 99
b: 99
0 Response to "Increment and Decrement Operators in C++"
Post a Comment