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.
- lvalue and rvalue in C language
- Execution of printf with ++ operators
- sizeof operator in C
- Bitwise Operators in C/C++
- Difference between ++*p, *p++ and *++p
- To find sum of two numbers without using any operator
- A comma operator question
- Order of operands for logical operators
- Increment (Decrement) operators require L-value Expression
- Precedence of postfix ++ and prefix ++ in C/C++
- Modulus on Negative Numbers
- C/C++ Ternary Operator - Some Interesting Observations
- Comma in C and C++
- Evaluation order of operands
- Operands for sizeof operator