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.
- Comma operator should be used carefully
- A comma operator question
- lvalue and rvalue in C language
- Comma in C and C++
- new vs operator new in C++
- map operator= in C++ STL
- map::operator in C++ STL
- set operator= in C++ STL
- list::operator= in C++ STL
- forward_list::operator= in C++ STL
- array::operator[ ] in C++ STL
- vector::operator= and vector::operator[ ] in C++ STL
- unordered_multiset operator = in C++ STL
- deque::operator= and deque::operator in C++ STL
- multimap::operator= in C++ STL