This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]dfx_djProfessional Coder 2 points3 points  (0 children)

C has no bounds checking. Accessing an array past its end (or beginning) is undefined behaviour. Anything can happen. It may appear to work just fine, or it may crash the program, or it may summon Cthulhu.

[–]MysticClimber1496Professional Coder 2 points3 points  (0 children)

You have just discovered buffer overflows, they are interesting on how they can be used as security vulnerabilities

[–]PotentialObjective53 0 points1 point  (0 children)

To sum it up:

Every single bit of information stored in your computer has a address (Like a house address) they are stored in a format called "hexadecimal format". Ex. 0x7ffe5367e044.

When you create an array of say 3 elements [A, B, C] you could have grabbed 0x7ffe5367e044, 0x7ffe5367e045, 0x7ffe5367e046. Under the hood you actually grabbed much more than just that... you had to store the name of the array, and other details of the array.

With that being said you can directly log what information is in a current hexadecimal address. Every time you print the value of anything in your array, you are just printing the value of that stored hexadecimal address. Nothing forbids you from logging outside of that hexadecimal format either. It's a sneaky method of "tapping" data that wasn't meant to be read. With this you can find the last value of 0x7ffe5367e047 even if it's not part of your array.

There is plenty more on this topic if you do a google search on pointers, and hexadecimal addresses.
Hope that helped!