+ 1

Printing array problem . See full Question in description.

I have an array of size 5... i commanded the computer to print the 6th element . It must show error, but it prints a garbage value . can any one explain why ?

11th Apr 2017, 11:40 AM
cool_boy12344
cool_boy12344 - avatar
3 odpowiedzi
+ 6
assume it's an array of ints (4 bytes each) [1,2,3,4,5] and assume that first address is 100 addr 100 104 108 112 116 120 124 ...... value [1] [2] [3] [4] [5] as you can see the memory is sequental, so you simply accesed memory at address 120 which is garbage.
11th Apr 2017, 12:13 PM
Burey
Burey - avatar
+ 2
Some languages does not check array bounds. If you are using C++ this is your case.
11th Apr 2017, 12:25 PM
Jeth
Jeth - avatar
+ 1
Thanks Burey , you cleared my doubt
11th Apr 2017, 7:57 PM
cool_boy12344
cool_boy12344 - avatar