Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comma operators and assignment operators - return values

Tags:

c++

c

The following code segment get an output of 32, I am kind of confusing why?

 int i=(j=4,k=8,l=16,m=32); printf(“%d”, i); 
like image 226
user288609 Avatar asked Nov 29 '22 05:11

user288609


1 Answers

Start reading inside the first set of parentheses.

The comma operator evaluates each of several expressions subsequently. It returns the return value of the last expression - in this case, it is 32, because the return value of an assignment is the value assigned.

http://en.wikipedia.org/wiki/Comma_operator

like image 98
relet Avatar answered Feb 11 '23 12:02

relet