This code when executed displays the expected output but prints segmentation fault (core dumped) at the end :
string str[4] = {
"Home",
"Office",
"Table",
"Bar"
};
for (int i = 0; i<5; i++)
{
cout << str[i] << "\n";
}
Output:
Home
Office
Table
Bar
Segmentation fault (core dumped)
What is the signinficance of segmentation fault (core dumped). I searched and it seems an error like that occurs when you try to access unallocated memory, so, what's wrong with the above code?
you should write:
for (int i = 0; i<4; i++) //0,1,2,3 = total 4 values
{
cout << str[i] << "\n";
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With