Why does this compile and why is the answer zero? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
20th Nov 2019, 10:50 PM
Sonic
Sonic - avatar
5 Answers
+ 6
Federico 🐺 thanks for the links.
21st Nov 2019, 2:00 AM
Sonic
Sonic - avatar
+ 6
Federico 🐺 in real life I would have never written such code if not for a challenge question I encountered here? See below. https://www.sololearn.com/post/179198/?ref=app
21st Nov 2019, 2:02 AM
Sonic
Sonic - avatar
+ 4
I'm especially surprised that line 6 does not cause an error.
20th Nov 2019, 10:51 PM
Sonic
Sonic - avatar
+ 1
My guess is that it’s probably getting 0 as the value of whatever was stored in the memory address located just before the array. C++ doesn’t seem to care about where its arrays are being indexed at lol
21st Nov 2019, 12:49 AM
nspaceLB_
nspaceLB_ - avatar
- 1
Becuz you can't put -1
22nd Nov 2019, 6:04 PM
Iván Cabaña
Iván Cabaña - avatar