Home > Backend Development > C++ > 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
Release: 2023-09-01 16:29:15
forward
957 people have browsed it

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;
Copy after login

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;
}
Copy after login

Output

C is : 7
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template