可以在嵌套的 for 循环中使用双括号吗?

Can you use double brackets in a nested for loop?

我的问题的意思是,如果我有一个像

这样的嵌套 for 循环
for(int i = 0; i < 10; i++)
{
    for(int j = 0; j < 10; i++)
    {
        printf("%d\n"___);
    } 
}

我会在空白处填什么?如果我已经声明了一个数组,[i][j] 会是非法的吗?

你的问题确实不清楚。但据我了解,你有一些二维数组,你想打印数组的内容。

你必须已经定义了数组int arr[10][10],然后你才可以使用,

printf("%d\n", arr[i][j]);

根据你的问题,我不确定你到底坚持了什么,所以我做了一个带有注释的最小 C 程序

我声明了一个 int 数组,其第一维和第二维至少为 10,因为您从 0 到 9(含)迭代 ij。这是为了避免迭代时出现越界问题

数组的元素没有在程序中初始化。当您 运行 它时,该程序可能会打印全零。也有可能是它打印了内存中恰好有的其他值(因为数组值没有初始化)

最后我在 for 循环外声明了 ij 以防万一这就是您遇到的问题

#include <stdio.h>

int main(int argc, char** argv) {
    // Declare an array
    // Note that both dimensions are at least 10
    // Also note that none of the values are initialized here
    int myArray[10][10];

    // Both i and j are declared here rather than in the for loop
    // This is to avoid the following potential error:
    // error: 'for' loop initial declarations are only allowed in C99 or C11 mode
    int i, j;

    for (i = 0; i < 10; i++) {
        for (j = 0; j < 10; j++) {
            // Note that the values this prints are uninitialized
            printf("%d\n", myArray[i][j]);
        }
    }

    return 0;
}