其它数据类型

来源:互联网 发布:桌面壁纸软件哪个好 编辑:程序博客网 时间:2024/05/16 04:50

 Defined data types (typedef)


typedef char C;typedef unsigned int WORD;typedef char * pChar;typedef char field [50]; 


C mychar, anotherchar, *ptc1;WORD myword;pChar ptc2;field name; 

联合


union union_name {  member_type1 member_name1;  member_type2 member_name2;  member_type3 member_name3;  .  .} object_names;

union mytypes_t {  char c;  int i;  float f;  } mytypes;

mytypes.c

mytypes.i

mytypes.f


union mix_t {  long l;  struct {    short hi;    short lo;    } s;  char c[4];} mix;


union mix_t {  long l;  struct {    short hi;    short lo;    } s;  char c[4];} mix;

匿名联合


struct {  char title[50];  char author[50];  union {    float dollars;    int yen;  } price;} book;

struct {  char title[50];  char author[50];  union {    float dollars;    int yen;  };} book;

book.price.dollarsbook.price.yen

book.dollarsbook.yen

枚举 

Enumerations (enum)



enum enumeration_name {  value1,  value2,  value3,  .  .} object_names;

enum colors_t {black, blue, green, cyan, red, purple, yellow, white};

colors_t mycolor; mycolor = blue;if (mycolor == green) mycolor = red; 

enum months_t { january=1, february, march, april,                may, june, july, august,                september, october, november, december} y2k;