C++源码 : 结构与联合 (STRUCT and UNION)

//C++源码 :  结构与联合 Example for (STRUCT and UNION)
   //
  
#include <iostream>
using namespace std;

void fun1();

main()
{
fun1();
}

void fun1()
 {
  const int nameLen=8;
  typedef struct  person
      {
       char name[nameLen];
       int  Year;
       int  born;
       char Sex;
       }  PP;
  PP WXJ;  //C++中:  用 person WXJ; 也可以
 
  char nnnn[]="XJ Wang       uwqyuuiuiiuiuiuiuiiihhjjh";

for (int ii=0;ii<nameLen;ii++)
  {
    //WXJ.name[ii]=ii;
      WXJ.name[ii]=nnnn[ii];
  }

//  WXJ.name[]={w,a,n,g};
  WXJ.Year=27;
  WXJ.born=1969;
  WXJ.Sex='N';
  cout<<"\n\n        You are Wellcome !   Example for (STRUCT and UNIO)  \n\n";
 
  for (int ii=0;ii<nameLen;ii++)
  cout<<WXJ.name[ii];  
 
  cout<<"\n"<<WXJ.Year<<"\n"<<WXJ.born<<"\n"<<WXJ.Sex<<"\n\n\n";
 
  }

(0)

相关推荐