Increment and Decrement Operators
Increment and Decrement Operators
DECREMENT OPERATORS
C++ provides various different types of
Operators in order to compute mathematical
and logical statements and expressions in the
program. Increment Operator and Decrement
Operator are one such type of Unary
Operators in C++ which are used to add or
subtract the value of 1 from the operand
respectively.
Definition
#include<iostream>
Using name space std;
Int main()
{
Int x = 15 ; Int y = 30 ;
++x ;
y++ ;
cout << x << endl << y ;
}
Note 2
#include<iostream>
Using namespace std;
int main()
{
int x = 15 ;
int y = 30 ;
-- -- x ;
y -- -- ;
cout << x << endl << y ;
}
Example 2:
int main()
{
int x = 10 ;
int a ;
cout <<"Value of x = "<< -- -- x << endl ;
a = x -- -- ;
cout <<"Value of a = "<< a << endl ;
cout <<"New Value of x = "<< x << endl ; return 0;
}
Output
Value of x = 9
Value of a = 9
New value of x = 8
Explanation: