U8 pointer forced conversion to u32, u8 pointer forced u32
A u8 type array. the pointer p points to the first element of the array, and the pointer q points to the first element of the array, q is of the u32 * type. What are the values of * p and * q?
Typedef unsigned long u32; typedef unsigned short 2010; typedef unsigned char u8; int main (void) {u8 I; u8 tab [4] = {0x12, 0x34, 0x56, 0x78}; u8 * p = tab; u32 * q = (u32 *) p; for (I = 0; I <4; I ++) {printf ("% # x", tab + I); printf ("% # x \ n", tab [I]);} printf ("\ n "); for (I = 0; I <4; I ++) {printf ("% # x", p); printf ("% # x \ n", * p ); p ++;} printf ("\ n"); printf ("% # x \ n", * q); return 0 ;} /*************************************** * ******** the output result in VC ++ 6.0 is: 0x18ff40 0x120x18ff41 0x120x18ff41 0x340x18ff42 0x560x18ff43 using any key to continue *************************** **********************/
Because p is a pointer to the u8 type, * p value is the element value corresponding to the array tab.
Q is a pointer to the u32 type, so * q value is the value of the u32 type. The data storage order of CPUs of different architectures is different in the memory. It is tested that the STM32F05x mode is a small-end mode, so * q = 0x78563412