Are negative array indices or 0 sized arrays valid in C++ ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

Are negative array indices or 0 sized arrays valid in C++ ?

Why does this code compile and output 0? #include <iostream> using namespace std; int main() { int a[0]; cout << a[-1]; return 0; }

30th Mar 2019, 11:09 AM
Sonic
Sonic - avatar
1 Answer
+ 4
Thanks ~ swim ~. Personally I think they should not have compiler dependent questions in challenge quizzes but unfortunately we have some.
30th Mar 2019, 12:12 PM
Sonic
Sonic - avatar