What does the operation c=a+++b mean in C/C++?
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-
using namespace std;
int a = 2, b = 5;
c = a+++b;
cout << "C is : " << c;
C is : 7
Here the first option is taken.
Published on 09-Apr-2019 09:34:46
- Related Questions & Answers
- What does the restrict keyword mean in C++?
- What does the volatile keyword mean in C++?
- What does the explicit keyword mean in C++?
- What does “dereferencing” a pointer mean in C/C++?
- What does the [Flags] Enum Attribute mean in C#?
- What does int argc, char *argv mean in C/C++?
- What does the two question marks together (??) mean in C#?
- What does int argc, char *argv mean in C++?
- What does 'using namespace std' mean in C++?
- What does it mean when a numeric constant in C/C++ is prefixed with a 0?
- Does Ternary operation exist in MySQL just like C or C++?
- What does the slash mean in a MySQL query?
- Larger of a^b or b^a in C++
- Program to find N-th term of series a, b, b, c, c, c…in C++
- What does these operators mean (** , ^ , %, //) ?