Each element of an integer array is stored continuously in memory. The storage method of each integer element depends on the machine hardware.
1. Array elements are stored continuously, with addresses from low to high.
For example, the character array char a[10];
It has 10 elements, ranging from a[0] to a[9], with consecutive addresses. If the starting address of a is 0x1234, then the subsequent addresses are 0x1235, 0x1235...0x123D.
2. The specific storage method of each element depends on the CPU. There are two types:
1. Little Endian:
Storage the low-order byte at the starting address (low-order addressing), and the low-order byte of the address stores the low-order byte of the value. The high bits of the address store the high bits of the value.
At present, most CPUs are stored in this way, including Intel and the most common arm on mobile terminals.
For example, if the 4-byte integer value is 0x12345678, it will be stored in the memory as:
0x78 0x56 0x34 0x12
2. Big endian ( Big Endian):
Contrary to little endian, the high-order byte is stored at the starting address (high-order addressing), the low-order byte of the address stores the high-order byte of the value, and the high-order byte of the address stores the low-order byte of the value.
The previous example is stored as:
0x12 0x34 0x56 0x78