Why I am getting this type of output? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Why I am getting this type of output?

https://code.sololearn.com/chNOXnomFcTu/?ref=app

15th Mar 2021, 12:35 PM
Atul [Inactive]
5 Answers
+ 2
When you printing myArr[x] , x=5 which is undefined value and x=5 is out of range for index value for the array.. its undefined garbage value displaying..
15th Mar 2021, 12:42 PM
Jayakrishna 🇮🇳
+ 2
15th Mar 2021, 1:11 PM
Atul [Inactive]
+ 1
Run it multiple times to get different outputs
15th Mar 2021, 12:35 PM
Atul [Inactive]
0
You're welcome..
15th Mar 2021, 1:24 PM
Jayakrishna 🇮🇳
0
To avoid out of bound calls, you can use STL std::array from <array>. This template class container has member function "at()" which throws an exception when you try to call out of bound position
15th Mar 2021, 9:16 PM
Michal Doruch