Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

1 Answer
Vrundesha Joshi

Let us consider in C or C++, there is a statement like:

c = a+++b;

Then what is the meaning of this line?

Well, Let the a and b are holding 2 and 5 respectively. this expression can be taken as two different types.

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

There are post increment operator, as well as pre increment operator. It depends on how they are used.

There are two basic concepts. The precedence and the associativity. Now if we check the expression from left to right, so the result will be these two.

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

Now let us check which option is taken by the compiler-

Example Code

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

Output

C is : 7

Here the first option is taken.

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.