Say,the address of a variable 'a' is 64488 and aptr is a pointer variable such that int*aptr; aptr=&a; So,64488 is stored in aptr pointer variable.What I don't understand is how can aptr store 64488 in just a single byte (8 bits) because the maximum decimal value a byte can store is 255
On 32 bit systems such as IDE50 memory addresses (pointers) are 32 bits as the name would suggest; likewise on 64 bit systems the memory addresses are 64 bits.
- 32 / 8 = 4
- 64 / 8 = 8
So a pointer is not 4 or 8 bits, but instead 32 or 64 bits, which is equal to 4 or 8 bytes. This leaves plenty of room for addresses, in fact a 32 bit system can store 4,294,967,295 different memory locations, meanwhile a 64 bit system can store a whole 9,223,372,036,854,775,807 different memory locations!
What do you think is actually only a single byte? I'm guessing that you think that since a pointer points at an address, and that every byte has an address, that only one byte is available at that address.
In fact, when memory is allocated with a malloc, an amount of memory defined in the command is allocated. If the pointer points at another var, as in your example, the system has already allocated the correct amount of memory for that var type. It would be pretty useless to only be able to use one byte! ;-)
Finally, when a pointer is created, it has a type and uses the appropriate number of bytes. In your example,
int* aptr; is a pointer to an integer type, so it always assumes that the 4 or 8 bytes, depending on architecture, stored at that address is available and used for storing an integer, not just the byte at the actual address.