Comma operator in c -
this question has answer here:
- what comma operator , do? 8 answers
#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
Post a Comment