Tuesday 15 June 2010

Memory addresses, pointers, variables, values - what goes on behind the scenes -


This is going to be a very full question, but since I started learning about pointers, Behind the scenes when a program is run behind.

As far as I know, computer memory is generally considered to be a long strip of memory which is evenly divided into different bytes. Certainly pictures, such as the emergence of the following metaphors:

p_to_c pa alloc

One thing I was thinking, I remember myself, I am convinced that it is no coincidence that the memory address would appear as hexadecimal values ​​of 8 digits (eg / 00 EB 05748) Are there. Why is it like this?

In addition, when I declare a variable X, what is happening at the memory level? Does the compiler reserve a random address for storing (+ Still many types of addresses are required for the variable type)?

Now assume that X is an unsigned ent that holds 2 bytes of memory (i.e. value from 0 to 65536). When I declare X = 12, what's going on? What is it that I am making 12? When I attract ideological figures, I usually have a box for an address pointing to a variable (x) (which is called & x) which seems to be nothing, and I Believe it can not be completely accurate what is happening.

And what is happening at the binary level? Is the address considered as 00EB5748 111010110101011101001000 and stores the value of 12 or 12 somewhere?

Mostly my illusion & amp; Curiosity arises from the relationship between memory addresses and actual values ​​(e.g. / 12, 'A', -355.2). As another example, suppose that our address is pointing at around 900 EB 5748, which is 115 in accordance with ASCII charts. Is there a description describing the situation that stores value 115 in 1 byte, by flipping the appropriate 1s and 0s in that position in memory?

Just open any book You will see the page Every page has a number, consistently from the number of pages continuously Are counted. Do you have any confusion with the numbered pages? I do not care. You should not be confused with computer memory. Before the computer era, books were the memory storage storage device, the original concept is obtained from computer memory books: the book has pages - & gt; Computer memory contains memory cells, the book has page numbers - & gt;

  • One thing I was thinking, remembering myself, what do the memory addresses reflect?

    Number is the number of memory cells, like every page in the book.

    • Besides, when I declare a variable x, what is happening at the memory level? Does the compiler reserve a random address for storing (+ Still many types of addresses are required for the variable type)?

      The memory manager captures some memory cells and tells the address of the reserved cell first for the compiler. The compiler adds the name and the type of variable with this address.

      • When I declare x = 12, what's going on?

        When you declare a variable x , memory cells were reserved for this variable, now you write 12 in these memory cells . Note that 12 is binary coded in any way, depending on the type of variable x . If x is an unsigned integer that captures 2 memory cells, then one cell contains 0, others will contain 12. Because 12 binary integers represent

          0000 0000 0000 1100. _______ | | _______ | Cell cell   

        If 12 is floating-point number, then it will be coded in another form.

No comments:

Post a Comment