gpt4 book ai didi

c - C 中的简单矩阵

转载 作者:行者123 更新时间:2023-11-30 14:56:30 24 4
gpt4 key购买 nike

我不明白为什么以下代码会生成 43213987

#include <stdio.h>

int main(){

int a[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};

for(int i=0; i<3; i++)
for(int j=3; j>=0; j--)
if(i%2==0)
printf("%d", a[i][j]);

return 0;
}

如何访问屏幕上打印的第二个3a[2][3] 如何合法?

最佳答案

How a[2][3] can be legal?

不,这是不合法的。这是未定义的行为,因为超出了数组范围。

c99 草案标准部分Annex J.2 J.2 未定义的行为包括以下几点:

An array subscript is out of range, even if an object is apparently accessible with the given subscript (as in the lvalue expression a[1][7] given the declaration int a[4][5]) (6.5.6).

关于c - C 中的简单矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44648991/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com