c++ - what is inside skipped memory address? -
we know integer variable take 4 (byte) memory address. wonder, if initialize integer variables , make pointer it. can value of pointer (which have address of variable: 0x22fef8 in computer). how memory address after 0x22fef8 0x22fef9, 0x22fefa, 0x22fefb? in there? value of variable if dereference address? how access them?
thank you.
you're right: in 32-bit computer integer takes 4 bytes. in c, can expressed following code:
int = 0x12345678; int *p_i = &i;` if p_i gets value 0x22fef8, p_i++ become 0x22fefc since point next integer. if want see what's in bytes make i, need use different pointer:
typedef uint_8 byte; byte *p_b = (byte *)&i;` that means change pointer-to-int &i represents , typecast pointer-to-byte. still have value 0x22fef8 since that's first byte of i - if p_b++ change 0x22fef9. , note if print out original value of *p_b (that is, byte pointing to), not give same value i. depending on computer, print out either first byte or last byte: 0x12 or 0x78, or @ least decimal versions thereof.
this due "endianness" of computer, affects storage of multi-byte values. little-endian computers x86 store littlest part of value first - 0x78 - while power pc computers store biggest part of value first - 0x12.
Comments
Post a Comment