

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
How does the Comma Operator work in C++
The purpose of comma operator is to combine several expressions. The value of a comma-separated list of expressions is the value of the right-most expression. Comma's effect is to allow a sequence of operations to be performed.
The values of the other expressions are discarded, which means that the expression on the right side will become the value of the entire comma-separated expression.
example
The following program illustrates the working of comma operator −
#include <iostream> using namespace std; int main() { int i, j; j = 10; i = (j++, j+100, 999+j); cout << i; return 0; }
Output
This gives the output −
1010
Here is the procedure how the value of i gets calculated: j starts with the value 10. j is then incremented to 11. Next, j is added to 100. Finally, j (still containing 11) is added to 999, which yields the result 1010.
- Related Questions & Answers
- How does * operator work on list in Python?
- How does the * operator work on a tuple in Python?
- How does in operator work on list in Python?
- How does concatenation operator work on list in Python?
- How does repetition operator work on list in Python?
- How does del operator work on list in Python?
- How does concatenation operator work on tuple in Python?
- How does the repetition operator work on a tuple in Python?
- How does the del operator work on a tuple in Python?
- How does comparison operator work with date values in MySQL?
- How does the 'in' operator work on a tuple in Python?
- Comma operator in C/C++
- JavaScript : Why does % operator work on strings? - (Type Coercion)
- How does the Microstrip antenna work?
- How does the Selenium WebDriver work?
Advertisements