+ 1
#include<stdio.h> void main() { int a; a=(1,2,3); printf("%d",a); }
the output is 3. can anyone tell me that why the last value of parenthesis is assigned to a ?
1 ответ
+ 1
Next time, please specify programming language. Almost went into C++ with this one. Also, put the code inside the description, or make a new code and post it here.
The comma operator in C is a sequence point which means that the expressions separated by the comma are executed from left to right.
The value of the whole expression is the value of the rightmost expression, in your case 3, which gets assigned to the variable a.
This should explain why it is set to 3.
Since the expressions in your example don't have side effects, the use of the comma separator here makes no sense whatsoever.
Source
https://stackoverflow.com/questions/1428083/assignment-of-two-values-in-parentheses-in-c