0

Why there is no output?

#include <iostream> using namespace std; int main() { string arr [2] = {"12","st"}; cout << arr[2]; return 0; }

5th Oct 2019, 6:30 PM
Neon
Neon - avatar
2 Respostas
+ 8
That's because arr[2] doesn't exist. Your array has a size for 2 elements. Since array indexing starts from 0, so you can access first element/index by arr[0] and similary second one like arr[1]. Also note that compiler will give 'Index out of bound' or 'Memory access violation' (not sure which one of them) error.
5th Oct 2019, 6:57 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 1
I forget about it.Thank you veru much!
6th Oct 2019, 4:40 AM
Neon
Neon - avatar