In your 3 cases, before the printf statement, the 4 first bytes of the arr
array (in hexadecimal format) are: FF D8 FF E0, which corresponds to 255 216 255 224.
Here are explanations of each case:
-
arr[0]
has uint8_t type, so its 1-byte value is 0xFF, soprintf("%i", arr[0]);
prints 255, which corresponds to 0xFF in signed decimal integer format required by%i
, integer size being 4 bytes. -
arr[0]
has uint16_t type, so its 2-bytes value is 0xFFD8, soprintf("%i", arr[0]);
prints 55551, which corresponds to 0xFFD8 in signed decimal integer format required by%i
, integer size being 4 bytes. Note that 0xFFD8 is interpreted with little-endianness (the byte 0xD8 is the MSB). -
arr[0]
has uint32_t type, so its 4-bytes value is 0xFFD8FFE0, soprintf("%i", arr[0]);
prints -520103681, which corresponds to 0xFFD8FFE0 in signed decimal integer format required by%i
, integer size being 4 bytes. Note that 0xFFD8FFE0 is interpreted with little-endianness (the byte 0xE0 is the MSB).
Note: I voluntarily changed “255 216 255 244” from your post into “255 216 255 224”. I think you made a typo.
solved Usage of uint_8, uint_16 and uint_32