In C and C++, comma (,) can be used in two contexts:
1) Comma as an operator:
The comma operator (represented by the token ,) is a binary operator that evaluates its first operand and discards the result, it then evaluates the second operand and returns this value (and type). The comma operator has the lowest precedence of any C operator, and acts as a sequence point.
2) Comma as a separator:
Comma acts as a separator when used with function calls and definitions, function like macros, variable declarations, enum declarations, and similar constructs.
The use of comma as a separator should not be confused with the use as an operator. For example, in below statement, f1() and f2() can be called in any order.
See this for C vs C++ differences of using comma operator.
You can try below programs to check your understanding of comma in C.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Result of comma operator as l-value in C and C++
- Comma operator should be used carefully
- A comma operator question
- Full screen OpenCV / GtK application in C++ running on Raspberry PI
- C++, OpenCV and Gtk3 Windows dev environment
- How to create an unordered_map of user defined class in C++?
- Sum of Bitwise-OR of all subarrays of a given Array | Set 2
- attributes in C++
- Find sum of a number and its maximum prime factor
- How to traverse a C++ set in reverse direction
- How to Read and Print an Integer value in C++
- How to Read and Print an Integer value in C
- Difference between Definition and Declaration
- Nested switch case