Structures

2018-03-01 10:58:06来源:oschina作者:Frost729人点击

分享

C++ allows you to drop the keyword struct when you declare structure variables:


struct inflatable
{
char name[20];
float volume;
double price;
};
struct inflatable goose;//keyword struct required in C
inflatable vincent; //keyword struct not required in C++
Union

A union is a data that can hold different data types but only one type at a time.A union can hold an int or a long or a double.The syntax is like that for a structure,but the meaning is different.For example:


union one4all
{
int int_val;
long lone_val;
double double_val;
};

You can use a one4all variable to hold an int,a long,or a double,just as you do so at different times:


one4all pail;
pail.int_val = 15;
cout<pail.double_val = 1.38;
cout<

相关文章

    无相关信息

最新文章

123

最新摄影

闪念基因

微信扫一扫

第七城市微信公众平台