How many byt开发者_开发技巧es can I store in one RAM address?
And what is the size of one pointer?
I'm just not sure about these basic concepts and I need a little help. Thank you all.
You can typically store one byte per memory location. (Older machines may have used non-octet word sizes, and those machines might store one nibble or 12 or 24 bits per memory location.) But these days, 8-bits is one byte, and one byte is one memory location, though it might not be the word size of the machine.
A pointer's size may vary: on 32-bit platforms, pointers are usually 4 bytes. On 64-bit platforms, pointers are usually 8 bytes. Older platforms had different sizes of pointers to allow programmers to more closely optimize the memory requirements of their programs. (I'm glad those days are gone.)
What confused me to no end when first starting C is that the memory location referenced by a pointer increments different amounts based on the datatype of the pointer.
char *c;
int *i;
When using an offset or incrementing the pointers (c+1
or i+1
) the compiler will add 1
for the char *
pointer and 4
or 8
for the int *
pointer. My assembler didn't provide such niceties, and it took me months to get the hang of "the C compiler knows the sizes of types, just trust it".
An pointer has usually 4 bytes on 32-bit systems and 8 bytes on 64-bit systems - but thats not fixed and may depend on the system.
An adress is just an position in your memory and an pointer refers to that. But the data can be more than one byte - the pointer just shows there the first byte is.
精彩评论