So, one day I forgot to put "max" before "() " in practice and got something like:
int a;
int arr[10] = {1,2,3,4,5,6,7,8,9,10};
for (int i=1; i<10; i++)
{
a = arr[i-1], arr[i]; //vs. a = (arr[i-1], arr[i]); 本地测试(gcc 8.1)
//前者取arr[i-1],后者取 arr[i]
}
after putting up a question here,
someone kindly pointed out how the comma operator works.
It seems to be something to be avoided, as it could be rather confusing and doesn't really have an exclusive functionality (tbd)
from https://en.cppreference.com/w/cpp/language/operator_other#Built-in_comma_operator

本文通过一个具体的C++编程实例介绍了逗号运算符的工作原理及其潜在的问题。作者分享了在实践中因忽略细节而产生的意外行为,并解释了逗号运算符的优先级及其可能导致的混淆。
最低0.47元/天 解锁文章
15万+

被折叠的 条评论
为什么被折叠?



