cpp16.cpp
来自「C++参考书」· C++ 代码 · 共 45 行
CPP
45 行
// Coded by plusir -- Dec.27.2002.
// Standard C++ Bible -- (P134-5-16)
#include <iostream>
using namespace std ;
union Holder
{
char holdChar ;
short holdInt ;
long holdLong ;
double holdDouble ;
} ;
void displayHolder( Holder, char * ) ;
int main()
{
Holder hld ;
hld.holdChar = 'X' ;
displayHolder( hld, "char" ) ;
hld.holdInt = 12345 ;
displayHolder( hld, "int" ) ;
hld.holdLong = 7654321 ;
displayHolder( hld, "long" ) ;
hld.holdDouble = 1.23 ;
displayHolder( hld, "double" ) ;
return 0 ;
}
void displayHolder( Holder hld, char *title )
{
cout << "---Initalized " << title << "---" << endl ;
cout << "holdChar = " << hld.holdChar << endl ;
cout << "holdInt = " << hld.holdInt << endl ;
cout << "holdLong = " << hld.holdLong << endl ;
cout << "holdDouble = " << hld.holdDouble << endl ;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?