c++编程问题

1、出现提示‘’ warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]‘’

#include <iostream>
#include <vector>
using namespace std;

int main{
    int a, b;
    a = 1;
    if(a==1){
        b = 0;
    }
    cout<<b<<endl;
}

出现原因是b在定义声明时没有赋值,之后赋值出现在if结构中,如果if无法进入则cout输出的b则是随机赋值的,因此给出警告。

猜你喜欢

转载自www.cnblogs.com/Kevin-HDS/p/11764173.html