Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How is each element of integer array stored in memory in C language?
How is each element of integer array stored in memory in C language?
Each element of an integer array is continuously stored in memory, and the storage mode of each integer element depends on the machine hardware.

First, array elements are all stored continuously, with addresses from low to high.

Such as the character array char a [10];

There are 10 elements, from a[0] to a[9], and the addresses are continuous. If the initial address of A is 0x 1234, the subsequent addresses are 0x 1235, 0x 1235...0x 123d.

Second, the specific storage mode of each element depends on the CPU. There are two kinds:

1, small end:

The low byte is stored in the starting address (low address), the low byte of the address stores the low byte of the value, and the high byte stores the high byte of the value.

At present, most CPUs are stored in this way, including the most common mobile terminals intel and arm.

For example, if the integer value of 4 bytes is 0x 12345678, it will be stored in memory as:

0x78 0x56 0x34 0x 12

2. Big end:

Contrary to the small end, the high byte is stored at the start address (high address), the low address stores the high value, and the high address stores the low value.

The previous example is stored as:

0x 12 0x34 0x56 0x78