gpt4 book ai didi

c++ - C4700 : uninitialized local variable

转载 作者:太空狗 更新时间:2023-10-29 23:26:26 25 4
gpt4 key购买 nike

当我编译这段代码时,它显示“错误 C4700:使用了未初始化的局部变量‘b’”。我不确定我现在必须做什么来解决这个问题。我既不是 IT 学生也不是技术人员,但我非常喜欢学习 C++,而且我正在自学。我已经为此工作了 1 天。

非常感谢

#include <stdio.h>
#include <iostream>

//A.
//1--
void InputArray(int *a, int &n)
{
printf("Insert n = ");
scanf("%d", &n);
a = new int[n];
for (int i=0; i<n; i++)
{
printf("Enter the key's a[%d] values: ", i);
scanf("%d",&a[i]);
}
}


void main()
{
int *b, m;
InputArray(b, m);
}

最佳答案

b 按值传递,这意味着将制作一个拷贝,但由于它未初始化,您会收到警告。简单地初始化它:

int *b = nullptr;

int *b = NULL;

关于c++ - C4700 : uninitialized local variable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21917424/

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