
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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