- : Increment - Decrement Operators :-
These are Unary Operators (For single Operands) used to increase or decrease the value of operand by adding or subtracting 1 respectively.
increment Operator -
increment Operator is used to increase the value of operand. Symbol of increment operator is double plus (++).
There are 2 types of increment operator -
(1) Pre-increment
(2) Post-increment
Pre-increment operator is used to increase operand value by 1, before assigning it to the expression. In pre-increment (++) used before operand. Ex:- (++a)
value actual value visible value in output
++10 11 11
Post-increment operator is used to increase operand value by 1, after assigning it to the expression. In post-increment (+ +) used before operand. Ex:- (a++)
value actual value visible value in output
10++ 11 10
___________________________________________________________
A program for Increment operator
#include <iostream>
using namespace std ;
int main ()
{
// declare integer variables
int a = 10;
cout<< "visible value of a after using Pre-increment = " << ++a <<endl; //Pre-increment
cout<< "visible value of a after using Post-increment = " << a++ ; //Post-increment
return 0;
}
______________________________
Output -
visible value of a after using Pre-increment = 11
visible value of a after using Post-increment = 10
___________________________________________________________
Decrement Operator -
Decrement Operator is used to decrease the value of operand by 1. Symbol of decrement operator is double minus (- -).
There are 2 types of increment operator -
(1) Pre-decrement
(2) Post-decrement
Pre-decrement operator is used to decrease operand value by 1, before assigning it to the expression. In pre-decrement (- -) used before operand. Ex:- (- - a)
value actual value visible value in output
- -10 9 9
Post-decrement operator is used to decrease operand value by 1, after assigning it to the expression.In post-decrement (- -) used after operand. Ex:- (a- -)
value actual value visible value in output
10- - 9 10
___________________________________________________________
A program for Decrement operator
#include <iostream>
using namespace std ;
int main ()
{
// declare integer variable
int a = 10;
cout<< "visible value of a after using Pre-decrement = " << ++a <<endl; //Pre-decrement
cout<< "visible value of a after using Post-decrement = " << a++ ; //Post-decrement
return 0;
}
______________________________
Output -
visible value of a after using Pre-decrement = 9
visible value of a after using Post-decrement = 10
___________________________________________________________
Must Read :-
What is Operator in Programming Language
What is Arithmetic Operator in Programming Language
What is Relational Operator in C, C++ programming languages
What is Logical Operators in C, C++ Programming Language (English Explanation)
What is Logical Operator in C, C++ Language (Hindi Explanation)
What is Bitwise Operator in C, C++
No comments:
Post a Comment