The memory in the computer is the storage space in bytes . Each byte of memory has a unique number, which is called an address . As if the hotel is a room unit, each room has a unique room number, we can find the corresponding room according to room number.
1. Storage of variables
The number of bytes consumed by 1> is related to the type, and also to the compiler environment
2> Variable Instance
int B = 10;
int a = 134;
* Memory from large to small addressing
* Only binary forms are stored
* Each variable has an address: the address of the first byte is the address of the variable.
3> two ways to view memory addresses:%x and%p
4> viewing the binary form of integers
voidPutbinary (intN) { intBITS =sizeof(N) *8; while(bits-->0) {printf ("%d", n>>bits&1); if(bits%4==0) printf (" "); } printf ("\ n");}
2. Negative numbers in-memory storage
1 int Main () 2 {3 int B =-ten; 4 return 0 ; 5
In line 3rd, an integer variable is defined, and its value is-10. How is 10 stored in memory? In fact, any value is stored in the form of complement in memory.
- The complement of positive numbers is the same as the original code. Like 9, the original code and the complement are 1001.
- The complement of a negative number equals its positive number and the original code is reversed after +1. (The inverse means 0 change 1, 1 to 0)
Then-the 10 complement calculation process is as follows:
1> first calculates the binary form of 10:0000 0000 0000 0000 0000 0000 0000 1010
2> Reverse 10 binary: 1111 1111 1111 1111 1111 1111 1111 0101
3> results of reverse +1:1111 1111 1111 1111 1111 1111 1111 0110
Therefore, the integer-10 binary form in memory is: 1111 1111 1111 1111 1111 1111 1111 0110
3. Range of values
Memory analysis of "Learning notes" and "C language" variables