Using result of comma operator as l-value is not valid in C. But in C++, result of comma operator can be used as l-value if the right operand of the comma operator is l-value.
For example, if we compile the following program as a C++ program, then it works and prints b = 30. And if we compile the same program as C program, then it gives warning/error in compilation (Warning in Dev C++ and error in Code Blocks).
b = 30
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- A comma operator question
- Comma operator should be used carefully
- How can we use Comma operator in place of curly braces?
- lvalue and rvalue in C language
- Comma in C and C++
- How to input a comma separated string in C++?
- Program to Parse a comma separated string in C++
- Why overriding both the global new operator and the class-specific operator is not ambiguous?
- Operator Overloading '<<' and '>>' operator in a linked list class
- map operator= in C++ STL
- map::operator in C++ STL
- dot (.) operator in C/C++
- set operator= in C++ STL
- new vs operator new in C++
- alignof operator in C++
- multimap operator = in C++ STL
- bitset operator in C++ STL
- unordered_set operator!= in C++ STL
- unordered_set == operator in C++ STL
- unordered_map operator in C++ STL