Introduction to Increment & Decrement Operators in C++ Programming Language

 Increase and Decrement Operators in C++




Increase Administrators (++)


( ++ ) is use as the augmentation administrator in C++ Programming Language.


Increase administrator is use to increment or add 1 worth of Variable.


Increase administrator could be use previously or after the Variable name.


For Instance :


int age++ ;


----or then again, - - -


int ++age ;


Increase administrators couldn't involve with Constants and Articulations in C++ Programming Language. Only Factors in C++ Programming Language could be augmented.


Increase administrator ( ++ ) is Unary Administrator.


Kind of Addition administrator:


There are following 2 sorts of Addition administrator


  • Postfix Addition Administrator
  • Prefix Addition Administrator


Postfix Addition Administrator:


A post-increase administrator is used to build the worth of a variable subsequent to executing the articulation in which the administrator is used. With the post-increase administrator, the worth of the variable is first used in an articulation and afterward increase 1 .


For Instance:


twofold age = 15 ;

twofold id ;

id = age++ ;


Prefix Addition Administrator:


A pre-increase administrator is used to expand the worth of a variable prior to executing the articulation wherein the administrator is used. With the pre-increase administrator, the worth of the variable is first addition with esteem 1 then use in an articulation.


For Instance:


twofold age = 15 ;

twofold id ;

id = ++age ;


Decrement Administrators (- - )


( -- ) is use as the decrement administrator in C++ Programming Language.


Decrement administrator is use to diminish or eliminate 1 worth of Variable.


Decrement administrator could be use previously or after the Variable name.


For Instance :


int age- - ;


----or then again, - - -


int - - age ;


Decrement administrators couldn't involve with Constants and Articulations in C++ Programming Language. Only Factors in C++ Programming Language could be decremented.


Decrement administrator ( - - ) is Unary Administrator.


Kind of Decrement Administrator:


There are following 2 kinds of Decrement administrator


Postfix Decrement Administrator

Prefix Decrement Administrator


Postfix Decrement Administrator:


A post decrement administrator is used to diminish the worth of a variable subsequent to executing the articulation in which administrator is utilized. With the post decrement administrator, the worth of the variable is first utilized with in an articulation and afterward esteem 1 decrement.


For Instance:


twofold age = 15 ;

twofold id ;

id = age- - ;


Prefix Decrement Administrator:


A pre decrement administrator is used to diminish the worth of a variable prior to using the variable. With the pre decrement administrator, the worth of the variable is first decrement with esteem 1 then use in an articulation.


For Instance:


twofold age = 15 ;

twofold id ;

id = - - age ;


Lets See following Code for better comprehension of Addition and Decrement Administrators in C++ Programming Language.




Code in C++


#incorporate <iostream>

utilizing namespace sexually transmitted disease ;

int principal( ) {

    int age = 17 ;

    cout << " Age is " << age << endl ;

    cout << " Presently age after postfix increase administrator = " << age++ << endl ;

    cout << " Presently age after prefix increase administrator = " << ++age << endl ;

    cout << " Presently age after postfix decrement administrator = " << age- - << endl ;

    cout << " Presently age after prefix decrement administrator = " << - - age << endl ;

    return 0 ;

}


Result of Above code is following


Age is 17

Presently age after postfix increase administrator = 17

Presently age after prefix increase administrator = 18

Presently age after postfix decrement administrator = 17

Presently age after prefix decrement administrator = 16


I want to believe that You can undoubtedly Comprehend and Realize this Article


Good luck 😇

Post a Comment

0 Comments