---
title: "C语句结构体"
author: "linsea"
date: "2009-09-18T17:00:36Z"
tags: []
slug: "c"
draft: false
lastmod: "2009-09-18T17:00:36Z"
id: 471667
url: "https://linsea.iteye.com/blog/471667"
---

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

```
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;
```