【问题标题】:expression must have a constant value problem表达式必须有一个常数值问题
【发布时间】:2022-08-23 17:44:36
【问题描述】:

我在视觉中使用 c 为用户制作代码以输入数组的大小。 该代码在视觉上不起作用并给出错误。 但在像 repli 这样的网站上它可以工作。 我不明白该怎么做才能让它在视觉上工作

[![在此处输入图像描述][2]][2]

#include<stdio.h>
#include<time.h>
#include<string.h>
#include<math.h>

int main()
{
int m;
do
{
printf(\"please enter arry size--> \");
scanf_s(\"%d\",&m);
} while (m <= 1);

int arry[m];

for (int i = 0 + 1; i < m + 1; i++)
{

printf(\"%d,\", arry[i] = i);

}

    return 0;
}enter code here
  • 不要发布文本图片,将文本作为格式正确的文本发布。并正确缩进你的代码。话虽如此,您正在使用 Microsoft 编译器不提供的 VLA(可变长度数组)。快速而肮脏的修复:使用适当大小的固定大小数组,例如:int arry[1000];

标签: arrays c visual-studio dynamic-arrays replit


【解决方案1】:

本声明

int arry[m];

是 C 编译器有条件地支持的可变长度数组的声明。

看来您正在使用一个版本的 MS VS,其 C 编译器不支持可变长度数组,或者您需要更改项目的属性并选择 C ​​编译器的最新版本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-14
    • 2011-06-12
    • 2014-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-02
    • 2012-07-27
    相关资源
    最近更新 更多