gpt4 book ai didi

c - 不在阵列上

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

我有这个:

char board_game [3][3] = {0}; // The Board Game

之后我会这样做:

scanf("%d%d", &row, &col); // Get The Input And Put It In Row And Column
printf("%d",board_game[row][col]);

有一些我不明白的输出,该行是什么意思 board_game[row][col]

|    input    | output
| row | col |
|______|______|________
| 0 | 0 | 0
|------|------|--------
| 0 | 1 | 0
|------|------|--------
| 0 | 2 | 0
|------|------|--------
| 0 | 3 | 0
|------|------|--------
| 1 | 0 | 0
|------|------|--------
| 1 | 1 | 0
|------|------|--------
| 1 | 2 | 0
|------|------|--------
| 1 | 3 | 0
|------|------|--------
| 2 | 0 | 0
|------|------|--------
| 2 | 1 | 0
|------|------|--------
| 2 | 2 | 0
|------|------|--------
| 2 | 3 | 1 **WHY 1?**
|------|------|--------
| 3 | 0 | 1 **WHY 1?**
|------|------|--------
| 3 | 1 | 0
|------|------|--------
| 3 | 2 | 0
|------|------|--------
| 3 | 3 | 0
|------|------|--------

你能向我解释一下发生了什么事吗?

最佳答案

当索引只能在 0..2 之间时,它是越界且未定义的(偏移量:3, 3| 3, 0)

并且您在所有数组值的开头声明了 0

board_game[row][col] 表示该偏移量中数组的值

关于c - 不在阵列上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46666145/

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