结构struct

struct book_bank

{

  char title[20];

  char author[15];

  int pages;

  float price;

};

 

struct book_bank book1, book2, book3;

 

类型定义结构:

typedef struct

{

  type member1;

  type member2;

  ...

} type_name;

 

type_name variable1, variable2;

 

相同结构类型的两个变量可以像普通变量一样进行复制。但不允许对结构变量进行任何逻辑操作。

 

访问成员的3种方法:

typedef struct

{

  int x;

  int y;

} VECTOR;

VECTOR v, *ptr;

ptr = &v;

 

1.使用句点表示法  v.x;

2.使用间接表示法  (*ptr).x

3.使用选择表示法  ptr->x;

 

结构中的结构:

struct salary

{

  char name;

  char department;

  struct

  {

    int dearness;

    int house_rent;

    int city;

  }

  allowance;

}

employee;

 

也可以使用标记符名来定义内部结构:

struct pay

{

  int dearness;

  int house_rent;

  int city;

};

struct salary

{

  char name;

  char department;

  struct pay allowance;

};

struct salary employee[100];

 

结构与函数:

1.将整个结构的副本传递给被调用函数。

2.使用指针以参数形式来传递结构。

posted @ 2010-09-20 14:10  露初晞  Views(374)  Comments(0)    收藏  举报