C4700:未初始化的局部变量 [英] C4700: uninitialized local variable

查看:818
本文介绍了C4700:未初始化的局部变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我编译这个代码,它说我不知道我现在要做什么来解决这个问题。我不是一个IT学生或技术人员,但我非常喜欢学习C ++,我自己学习。我一直在这1天。

When I compile this code it says "error C4700: uninitialized local variable 'b' used". I'm not sure what I have to do now to fix this problem. I'm neither an IT student or technican but I very like to learn C++ and I'm learning it by myself. I've been on this for 1 day.

非常感谢

#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 是通过值传递的,这意味着将进行一个副本,但由于它没有初始化,你会收到警告。只需初始化它:

b is passed by value, which means a copy will be made, but since it's not initialized, you get the warning. Simply initialize it:

int *b = nullptr;

int *b = NULL;

这篇关于C4700:未初始化的局部变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆