

- 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
Comma in C and C++
In C or C++, the comma ‘,’ is used in different purposes. Here we will see how they can be used.
Comma as an Operator.
The comma operator is a binary operator, that evaluates its first operand, and then discards the result, then evaluates the second operand and returns the value. The comma operator has the lowest precedence in C or C++.
Example
#include<stdio.h> int main() { int x = (50, 60); int y = (func1(), func2()); }
Here the 60 will be assigned to x. For the next statement, the func1() will be executed first, then the second one will be executed.
Comma as a Separator.
During function call or definition, it acts a separator. This is not like comma operator. When comma is used as separator, then all of the items separated by comma will be used, but for operator, it only gets the last one.
Example
#include<stdio.h> int main() { int x = 5, y = 10; void function(x, y); }
Here x and y both will be used as function parameters. The following program will be used to display how the comma operator is used.
Example
#include<stdio.h> main() { int a = 50; int b = (a++, ++a); printf("%d", b); }
Output
52
- Related Questions & Answers
- Comma operator in C/C++
- A comma operator question in C/C++ ?
- What is Comma operator in C++?
- Why do we use comma operator in C#?
- How does the Comma Operator work in C++
- Parsing a comma-delimited std::string in C++
- Split the sentences by comma and remove surrounding spaces - JavaScript?
- Python program to split a string and join with comma
- Split String with Comma (,) in Java
- What is Comma Operator (,) in JavaScript?
- What is Trailing Comma in PHP?
- C++ Program to take out integer from comma separated string
- Remove comma from a string in PHP?
- Regex to find string and next character in a comma separated list - MySQL?
- Count the number of comma’s in every record from a comma-separated value column in MySQL