Winter vacation Project 5-read Community & quot;, winter vacation 5-read Community

Source: Internet
Author: User

Winter vacation Project 5-read community, winter vacation 5-read Community

/** Copyright (c) 2014, School of Computer Science, Yantai University * All rights reserved. * file name: test. cpp * Author: Liu Chang * Completion Date: July 15, January 31, 2015 * version number: v1.0 ** Problem description: run the following program and explain the running result. * Input Description: * program output: output as required.

The Code is as follows:

# Include <iostream> using namespace std; union un {int I; char c [4] ;}; int main () {union un x; x. c [0] = 'a'; x. c [1] = 'B'; x. c [2] = 'C'; x. c [3] = 'D'; cout <x. I <endl; return 0 ;}

Running result:



Analysis:


Available in tables

17475 = 68*256 + 67;

16961 = 66*256 + 65;

1145258561 = 17475*256*256 + 16961;

A shared body contains several data members, each of which occupies a storage unit.


In fact, I still haven't figured out how to understand it. I just remembered this * 256 rule. If the passing God knows it, I beg for advice.


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.