Increment and Decrement Operators in C++

 Increment and Decrement Operators:



C++ also provides increment and decrement operators: ++ and -- respectively

  *Increment(++):Increments and value by 1

     

In increment operator again we have 2 types

  1.  Pre-Increment 
  2.  Post-Increment

Example :

 #include<iostream>  
 using namespace std;  
 int main()  
 {  
 int num=1;  
 //Pre-Increment  
 ++num;  
 //Post-Increment  
 num++;  
 }  


 Diffrence Between Pre-Increment and Post-Increment  :

* As name suggests Pre means it increments the value then assign and

* Post-increment means it assigns the value and increments 


Decrement Operator :

 Decreases it by 1

In decrement operator  also  we have 2 types

  1.  Pre-Decrement
  2.  Post-Decrement

Example :

 #include<iostream>  
 using namespace std;  
 int main()  
 {  
 int num=1;  
 //Pre-Decrement  
 --num;  
 //Post-Decrement  
 num--;  
 }  


In Simple:

a=4


cout<<a++ -> First prints and then increment

cout<<a-- -->First prints and then decrement

cout<<++a -->First increment and then prints

cout<<--a -->First decrement and then prints


AUTHOR : Rakshit Joshi Linkedin Profile ]

For Videos Join Our Youtube Channel: Join Now