mercredi 27 juillet 2016

segmentation fault (core dumped) when I try cout a const char *[i], what is the issue?

g++ compiler says:

segmentation fault (core dumped)

when this code is running:

#include <iostream>
using namespace std;

int main(){

const char *constantChars[3], *variableChars[3];
long int numbers[3];

for(int i=0; i<4; i++){
    constantChars[i] = "hello number: ";
    numbers[i] = i;
    variableChars[i] = (const char *) numbers[i];

    cout<<constantChars[i]<<variableChars[i]<<endl;
}

return 0;}

it crash when cout<<variableChars[i]<<endl in my for loop.

Aucun commentaire:

Enregistrer un commentaire