According to said system, the memory locations are just plain integers.
Yes, because they are just numbers.
But when I print out addresses in C/C++, they are displayed as an alphanumeric string.
You fail to mention what radix (or number base) these addresses are displayed in.
If the address was expressed in base 2, then there would be just 0s and 1s.
Back in the day octal representation was common, so an address could be represented with digits 0 through 7.
If the address was expressed in base 16, then the hexadecimal digits include 0 through 9 as well as the letters A through F. Is this the "alphanumeric string" you are referring to?
Plus, if they were actually just integers, wouldn't that be kind of problematic, since a register (say R1) containing a numeric value like 2000 could suddenly act as a pointer to a memory location just by enclosing it in parentheses? Like this: (R1) - >this would point to the memory location 2000
Coding an instruction or statement incorrectly (aka bugs) is always a problem in programming.
But memory address are just like integers.
That is how pointer arithmetic and calculations for table/structure displacements are accomplished.
A high-level programming language such as C will have distinct variable types to distinguish between a pointer
and an unsigned int
or unsigned long
, but when the data types have the same storage size, there is no actual difference in the binary structure. The restrictions on usage and conversion are merely to implement programming order and avoid potential bugs.
At the CPU level, any pointer
(or memory address) can be treated as an integer, and any integer can be treated as a memory address. They are all just numbers.
Bottom line: the CPU only knows how to process numbers. Everything has to be converted into (binary) numbers in order for a computer to process such "information".
So how exactly are memory addresses stored in memory?
A "memory address", aka pointer, is stored as a numeric value just like an integer (of the appropriate size).
Your premise that memory addresses are not numbers/integers is simply incorrect.
Thank you! I get it now. – Anchith Acharya – 2019-09-11T11:39:36.373