[Study Notes] [C Language] memory Analysis of variables, learning notes C language Variables
The memory in the computer isBytesThe unit of storage space. Each byte in the memory has a unique ID, which is calledAddress. As if the hotel is based on the room, each room has a unique room number, and we can find the corresponding room according to the room number.
1. Storage of Variables
1> the number of bytes occupied is related to the type and the compiler environment.
Void putBinary (int n) {int bits = sizeof (n) * 8; while (bits --> 0) {printf ("% d", n> bits & 1 ); if (bits % 4 = 0) printf ("");} printf ("\ n ");}
2. Storage of negative numbers in memory
1 int main () 2 {3 int B =-10; 4 return 0; 5}
The value of an integer variable is-10 in row 3rd. -10. How can I store the data in the memory? In fact, any value is stored in the memory as a complement.
- The positive complement is the same as the original code. For example, the source code and the complement code of 9 are both 1001
- The complement code of a negative number is equal to the original code of a positive number and then + 1. (Inversion means 0 to 1, 1 to 0)
The-10 complement code calculation process is as follows:
1> first calculate the binary form of 10: 0000 0000 0000 0000 0000 0000 0000 1010
2> decimal 10 binary: 1111 1111 1111 1111 1111 1111 1111 0101
3> result of reverse retrieval + 1111 1111 1111 1111 1111 1111 0110
Therefore, the binary format of integer-10 in the memory is: 1111 1111 1111 1111 1111 1111 1111 0110
3. Value Range