+ 9
Pls explain this code to me.
How does the code produce so unexpected output? https://code.sololearn.com/ctV53twJWpNh/?ref=app
2 ответов
+ 5
That's because the array has not been initialized, it has been declared, but it contains nothing. I couldn't quite explain why such memory dump is returned by the compiler, but it was bad.
You need to have values stored within the array before you can actually request one from it, here's a modified version of your code:
int main() {
string x[]={"My name", " is John Doe,", " Nice to meet you"};
cout << x[2];
return 0;
}
Hth, cmiiw
+ 5
garbage value is always unexpected