Comma operator in c -


this question has answer here:

#include<stdio.h>  int main(void) {    int a=(1, 2), 3;     printf("%d", a);    return 0; } 

output: 2
can 1 explain how output 2?

can 1 explain how output 2?

in statement

a = (1, 2), 3;    

, used comma operator. due higher operator precedence of = operator of , operator, expression operand (1, 2) bind =

(a = (1, 2)), 3;   

in case of comma operator, the left operand of comma operator evaluated void expression, right operand evaluated , result has value , type of right operand.

there 2 comma operators here. first comma operator in expression (1, 2), 1 evaluated void expression , 2 evaluated , assigned a.
side effect a has been taken place , therefore right operand of second comma operator 3 evaluated , value of expression (a = (1, 2)), 3 3.


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -