U8 pointer forced conversion to u32, u8 pointer forced u32

Source: Internet
Author: User

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

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.