ITeye博客

C语句结构体

linsea · 2009-09-18 17:00 · C/C++ · Markdown

一.声明一个结构体类型:

struct student
{
int num;
char name[20];
char sex;
int age;
float score;
char addr[30];
};  //注意这里有分号!!!

 

二.定义结构体类型变量
2.1

struct student student1, student2;

 

2.2 在声明类型的同时定义变量

struct student
{
int num;
char name[20];
char sex;
int age;
float score;
char addr[30];
} student1, student2;

 这种方式与如下的声明定义类似:
   int x, y, z;

 

2.3 直接定义结构类型变量
其一般形式为:

struct
{
  成员表列
}变量名表列;

 

struct
{
int num;
char name[20];
char sex;
int age;
float score;
char addr[30];
} student1, student2;

 即不出现结构体名,这有点儿像java里的匿名类声明.

 

 

三.用typedef定义类型

 

typedef int INTEGER;

typedef struct
{
 int month;
 int day;
 int year;
}DATE;

typedef struct
{
int num;
char name[20];
char sex;
int age;
float score;
char addr[30];
}STUDENT;

DATE birthday;
DATE *p;

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。