About storing addresses in memory for each byte of data type (for example, int)
First
Title, why the Good *p = &c is 1 Ah, why is 513, a start, I also feel quite surprised, back to listen to the teacher analyzed a bit just know how, but there is a problem not know how to, after the Internet to check the information, finally have some clues, but there is a problem ( The back said), cut let me.
To understand this program, first we need to understand the byte ordering of each data type
And the byte sort is divided into two kinds: one is big endian one is little endian
Big endian means that the high-order byte (high) is stored to the beginning of the allocated memory, while the little endian is a low-byte (status) store to the starting position allocated to memory.
Such as
Understand, and then talk about the topic, why is it 513?
because int *p This int is used for value, remember to use the value, and allocate memory to use the pointer is 8 bytes, this needless to say, in a system pointer is a fixed number of bytes, regardless of the data type, on my machine is 8 bytes, is generally 8 bytes.
Therefore, when the int type pointer p points to a pointer of type char, it gets not a byte, nor 8 bytes, which is 4 bytes (int type)
So from memory address ff10, take four bytes, well, the above Excel chart, that is, from 0000 0001 down four lines, in the high to low sort, there are several possibilities, but to get the result 513, there is only one possibility, is the first picture, and the sort is from bottom to top (high to low), Also, Java byte ordering is big Endien, and C is divided into CPU.
There is one more question, in the first picture, why is there a difference in memory address? Is there a way to get the memory address of each byte of a data type? Or is my concept a little blurry? Only personal opinion, if any, please do not give face point. Welcome to AC q1413557667
OC Learning Path-----kill pointer memory storage int type