OC Learning Path-----kill pointer memory storage int type

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.