Here, we are modifying an integer variable using a char pointer. The modification happens to the second byte (from the left of the starting location) and it is changed to 2.
i.e., 300 will be stored as (lower address on left) on a big endian machine
0 * 224 |
0 * 216 |
1 * 28 |
44 * 20 |
and as
44 * 20 |
1 * 28 |
0 * 216 |
0 *224 |
on a little endian machine.
In both the cases using the char pointer we point to the starting byte. And we are incrementing the starting byte by 2.
Ao, after the increment we have
0 * 224 |
2 * 216 |
1 * 28 |
44 * 20 |
on big endian architectures and
44 * 20 |
2 * 28 |
0 * 216 |
0 *224 |
on little endian architectures.
The respective values are 131372 and 556.
(This is the most common method of checking if an architecture is little endian or big endian)