
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
What is Comma operator in C++?
The purpose of the comma operator is to string together several expressions. The value of a comma-separated list of expressions is the value of the rightmost expression. Essentially, the comma's effect is to cause a sequence of operations to be performed.
The values of the other expressions will be discarded. This means that the expression on the right side will become the value of the entire comma-separated expression. For example −
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 Articles
- What is Comma Operator (,) in JavaScript?
- Comma operator in C/C++
- A comma operator question in C/C++ ?
- How does the Comma Operator work in C++
- Why do we use comma operator in C#?
- When is the comma operator useful in JavaScript?
- What is a Ternary operator/conditional operator in C#?
- Comma separated argument applicable for IN operator in MySQL?
- What is sizeof operator in C++?
- What is dot operator in C++?
- What is arrow operator in C++?
- What is pointer operator & in C++?
- What is Pointer operator * in C++?
- What is the ?-->? operator in C++?
- What is ternary operator in C#?

Advertisements