What does the operation c=a+++b mean in C/C++?



In C/C++, the expression c = a++ + b indicates that the current value of a is added to b, and the result is assigned to c. After this assignment, a is incremented by 1 (post-increment), which means the increment of a happens after its value is used in the expression.

Well, let a and b initialize with 2 and 5, respectively. This expression can be taken as two different types.

  • c = (a++) + b
  • c = a + (++b)

The above two expressions contain both post and pre-increment operators. It depends on how they are used.

In the above expression there are two basic concept precedence and associativity. So, compute the value of the above expression from the left to right.

  • c = (a++) + b -> 2 + 5 = 7
  • c = a + (++b) -> 2 + 6 = 8

Compute The Value of Expression c = (a++) + b in C++

In the following Example, we compute the above expression in the the C++:

#include <iostream>
using namespace std;
int main() {
   int a = 2, b = 5;
   int c;
   c = a+++b;
   cout << "C is : " << c;
}

Following is the output:

C is : 7

Compute The Value of Expression c = a + (++b )in C

In the following Example, we compute the above expression in the the C:

#include <stdio.h>
int main() {
   int a = 2, b = 5;
   int c;
   c = a + (++b);
   printf("C is : %d", c);
}

Following is the output:

C is : 8
Updated on: 2025-07-30T15:03:20+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements