How is the comma operator being used here? [duplicate]

隐身守侯 提交于 2019-11-28 11:36:34

This code is equivalent to this:

int a = 2 ; 
int b = a + 1 ;

First expression to the left of comma gets evaluated, then the one to its right. The result of the right most expression is stored in the variable to the left of = sign.

Look up the comma operator for more details.

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

(a = 2, a + 1); return 3 because in general case operator (a, b) return b, and calculation in (a, b) started from right to left. So, in your case, (a = 2, a + 1) return a + 1, and after operator a = 2 was executed a + 1 return 3.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!