Home  >  Article  >  Backend Development  >  In C/C++, what is the meaning of operator c=a+++b?

In C/C++, what is the meaning of operator c=a+++b?

WBOY
WBOYforward
2023-09-01 16:29:15932browse

In C/C++, what is the meaning of operator c=a+++b?

Let us consider that in C or C, there is a similar statement:

c = a+++b;

So what is the meaning of this line of code?

Okay, let a and b be 2 and 5 respectively. This expression can be viewed as two different types.

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

has post-increment operator and pre-increment operator. How they are used depends on how they are used.

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

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

Now let’s check Which option was selected 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 selected.

The above is the detailed content of In C/C++, what is the meaning of operator c=a+++b?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete