gpt4 book ai didi

c - 使用变量定义数组大小(代码块)

转载 作者:太空宇宙 更新时间:2023-11-04 04:20:54 25 4
gpt4 key购买 nike

我在“codeblocks”中使用了这段代码,它的效果非常好:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
int i,j, n, m;

printf("Input n & m: ");
scanf("%d %d", &n, &m);

int a[n][m];

//Reading Array Values
for(i = 0; i < n; i++)
{
for(j = 0; j < m; j++)
{
printf("a[%d][%d] = ", i, j);
scanf("%d", &a[i][j]);
}
}
//Displaying Array Values
for(i = 0; i < n; i++)
{
for(j = 0; j < m; j++)
{
printf("%d ", a[i][j]);
}

printf("\n");
}
}

但我看到一些主题,人们说这是一种实际上来自 gcc 编译器的选项。所以我想知道,我应该在未来使用这个还是错误的方式?我认为 vector 函数不会让我头疼,所以我决定这样做,而且效果很好。我想这只适用于我使用的 gcc 编译器版本。不过不管怎样,还是有问题还是可以顺利使用?

最佳答案

我认为您的代码中没有特定于 GCC 编译器的行为。我在 gcc 编译器上执行了相同的操作。你可以在这里查看结果:

jdoodle.com/a/biz

https://www.jdoodle.com/embed/v0/c/gcc-5.3.0/biz

<div data-pym-src="https://www.jdoodle.com/embed/v0/c/gcc-5.3.0/biz"></div>
<script src="https://www.jdoodle.com/assets/jdoodle-pym.min.js" type="text/javascript"></script>

关于c - 使用变量定义数组大小(代码块),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46918477/

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