C中多维数组变量增加错误

发布于 2025-01-04 18:29:21 字数 150 浏览 2 评论 0原文

我很想知道 C 中多维数组的行为增加如下:

int x[10][10];

y = x[++i, ++j];

我知道这是错误的方式。我只想知道编译器在这种情况下会做什么,以及如果程序员在他的代码中这样做会产生什么后果。

I have the curiosity to know the behaviour, in C, of a multidimensional array increased as below:

int x[10][10];

y = x[++i, ++j];

I know that is the wrong way. I just want to know what the compiler do in this case and what will be the consequence if a programmer do this in his code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情绪 2025-01-11 18:29:21

这就是逗号运算符,被误用了。 ++i, ++j 产生 j + 1 的值,并有 2 个副作用(修改 ij)。整个事情基本上意味着++i; y = x[++j]。哪个有效或无效,取决于 y 的类型。

如果程序员在他的代码中这样做会产生什么后果

?很可能其他程序员会给他/她投以杀气。

That is the comma operator, misused. ++i, ++j yields the value of j + 1 and has 2 side effects (modifying i and j). The whole thing basically means ++i; y = x[++j]. Which will work or not, depending on the type of y.

what will be the consequence if a programmer do this in his code

Well, most likely other programmers will give him/her murderous looks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文