+ 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 ?
3 ответов
+ 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.
+ 2
Some languages does not check array bounds. If you are using C++ this is your case.
+ 1
Thanks Burey , you cleared my doubt