A very simple test question of gele electronics is wrong !!!

Source: Internet
Author: User


Open the question picture and you will be able to see it.

Void main (void)

{Union unt

{Unsigned char UC [4];

Unsigned int UI;};

Union unt T;

T. UI = 0x12345678;

Printf ("% d \ n", T. UC [1]);}

 

The Community is rarely used in embedded development, so I didn't take a closer look at it during the review. Baidu once again, the variables in the community use the same bucket, that is, although I declare two variables in the Community, UC [4] and INT UI, their addresses are actually the same. In this question, the UC array uses four bytes, And the UI integer is exactly four bytes. Therefore, the UI Initialization is equivalent to the UC initialization. If the array type is changed to int, the space occupied by this community is 4*4 = 16 bytes. "Each member shares a piece of memory space, the length of a federated variable is equal to the longest length of each member." For more information, see the Baidu encyclopedia.

Big and small ends are the structure of the data stored by the processor. Big ends are the low-level data stored at the low-level address, while small-end high-level data is stored at the high-level address. Therefore, from this question, we can see that UC [0] = 0x78, UC [1] = 0x34, UC [2] = 0x56, UC [3] = 0x78, so the answer should be B. Unfortunately, after reading the exam yesterday, I chose, the problem turned out to be a mistake in marking the foot of the array. Sorry, let's learn the lesson.

A very simple test question of gele electronics is wrong !!!

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.