g ++ Compiler sagt:Segmentierungsfehler (Core Dumped), wenn ich versuche, ein const char * [i], was ist das Problem?
Segmentation fault (core dumped)
wenn dieser Code ausgeführt wird:
#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;}
es abstürzen, wenn cout<<variableChars[i]<<endl
in meiner for-Schleife.
Die Frage ist hier: 'for (int i = 0; i <4; i ++)' Ihr Index geht Grenzen aus. –