Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我很想知道在 C 中增加的多维数组的行为如下:
int x[10][10]; y = x[++i, ++j];
我知道那是错误的方式。我只想知道编译器在这种情况下做了什么,如果程序员在他的代码中这样做会产生什么后果。
那是逗号运算符,被滥用了。++i, ++j产生 和 的值j + 1有 2 个副作用(修改i和j)。整个事情基本上意味着++i; y = x[++j]。哪个有效或无效,取决于y.
++i, ++j
j + 1
i
j
++i; y = x[++j]
y
如果程序员在他的代码中这样做会有什么后果
好吧,很可能其他程序员会给他/她凶残的表情。