samedi 25 août 2018

Segmentation fault in for loop c++

Segmentation fault

include <iostream>

using namespace std;

int main()
{
    int a,b[a],total=0;
    cin>>a;
    for(int i=0;i<a;i++){
        cin>>b[i];
        total=total+b[i];
    }
    cout<<total<<endl;
    return 0;
}

Please help me find out why this code is segmentation fault

Aucun commentaire:

Enregistrer un commentaire