1. Byte and Address
To better understand the storage details of variables in memory, first recognize the "bytes" and "addresses" in memory.
1> memory in "bytes"
0x is the hexadecimal, not too tangled, can understand the numbers between the big who is small on the line
2> the bytes used by different types are not the same, the larger the data, the more the number of bytes required
2. 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 = 20;
Memory is addressed by large to small, giving precedence to variables with large bytes of memory addresses. B has a larger memory address than a
Each variable has an address: the address of the first byte is the address of the variable.
3> View memory Address:
int A;
printf ("A's address is:%p\n", &a);
4> Note
Do not attempt to use the value of a variable before it is initialized
int A;
printf ("A's value is:%d\n", a);
The above wording is not recommended.
3. Course Code
1#include <stdio.h>2 3 4 //1. Memory addressing from large to small, priority allocating memory addresses larger bytes to the variable5 6 //2. The more the variable is defined, the greater the memory address7 8 //3. Get the address of the variable:& variable name9 Ten //4. Output Address:%p One A //5. A variable must be advanced to initialize the line in order to use - - the intMain () - { - //memory addressing from large to small - intA =Ten; + - intb = -; + A intC; at - //& is an address operator that gets the address of the variable - //%p used to output addresses - //0x7fff56f09bc8 -printf"the address of A is:%p\n", &a); - //0X7FFF56F09BC4 inprintf"The address of B is:%p\n", &b); - //0x7fff56f09bc0 toprintf"the address of C is:%p\n", &c); + - //since the variable c is not initialized, it is not right to use it directly . the //int d = c + 1; * $ Panax Notoginsengprintf"the value of C is%d\n", c); - the return 0; + A}
Memory analysis of "Learning notes" and "C language" variables