Javatpoint Logo
Javatpoint Logo

Increment and Decrement Operators in C++

What is the definition of a C++ increment Operator?

The increment operator in C++ is a unary operator. The increment operator is represented by the symbol (++). The increment operator adds one to the value recorded in the variable. This operator is only applicable to numeric numbers

C++ increment Operators are classified into two types:

  • Pre-Increment
  • Post-Increment

1. The operator for post-increment (a++)

The postfix operator indicates that the value should be used first and then incremented. This signifies that the value is first utilized up for the operation, and then it is updated by one.

C++ Code:

Output

The value before employing the post increment operator is: 7
The value held by temp is: 7
The result of applying the post increment operator is: 8

2. The operator for pre-increment (++a)

The postfix operator specifies that the value be incremented before being used. This signifies that the value is incremented by one for the operation and then used by the variable.

C++ Code:

Output

The value before employing the pre increment operator is: 7
The value held by temp is: 8
The result of applying the pre increment operator is: 8

What exactly is a C++ decrement Operator?

The decrement operator in C++ is a unary operator. The increment operator is represented by the symbol (-). The decrement operator reduces the variable's value by one. This operator is only applicable to numeric numbers.

C++ decrement operators are classified into two types:

  • Operator for post-decrement
  • Operator for pre-decrement

1. Operator for post-decrement (a--)

The postfix operator indicates that the value should be used first, then decreased. This signifies that the value is first used up for the operation, and then it is reduced by one.

C++ Code:

Output

The value before employing the post decrement operator is: 7
The value held by temp is: 7
The result of applying the post decrement operator is: 6

2. Operator for pre-decrement (--a)

The postfix operator indicates that the value should be reduced before being used. This signifies that the value is reduced by one for the operation, and the value is then used by the variable.

C++ Code:

Output

The value before employing the pre decrement operator is: 7
The value held by temp is: 6
The result of applying the pre decrement operator is: 6






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA