c++ - C4700 : uninitialized local variable

标签 c++ console

当我编译这段代码时,它显示“错误 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/

相关文章:

c++ - OpenCV C++ 如何知道每行排序的轮廓数?

c++ - 在 C++ 中运行时在用户定义的类之间进行更改

C# 程序不会运行过去的对象实例

linux - 停止 tty 向下滚动

java - 使用 Java 清除控制台

intellij-idea - Intellij 控制台输出

c++ - 将变量引用转换为值?

c++ - 通过 vertex_index 属性访问顶点?

c++ - 如何释放通过 istream 阻塞的线程

c# - 结合 ConsoleModifiers 和 ConsoleKey