数组应用实例
#include <iostream.h>
main()
{ float a[]={1.1,2.3,3.5,7.8}; cout<<"第四个元素是:"; cout<<a[3]; }
建立一个描述水桶和锅的结构体
#include <iostream.h>
struct utensil { int no; //货号 float price; //器皿的价格 union {float diameter; //锅的口径 float volume; //水桶的容积 }; }pan,bucket; void main() { pan.no=20040615; pan.price=100; pan.volume=70; bucket.no=20040613; bucket.diameter=78; pan.diameter=70; bucket.volume=78; cout<<"桶的体积是:"<<bucket.volume<<"立方米"; cout<<"\n"; //换行 cout<<"锅的直径是:"<<pan.diameter<<"厘米"; cout<<"\n"; //换行 }