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.