typedef
的作用
重新命名變數:
typedef unsigned int Uint;//可以使用Uint代替unsigned int
定義新的資料型別
typedef struct Books{
char IBSN[20];
char author[30];
char name[40];
} Book;
int main(){
Book book;
//...
return 0;
}
typedef
和#define
的區別:
typedef
由編譯器執行,#define
由預編譯器處理
typedef
只能為型別定義符號名,#define
還可以定義常量
- 用
typedef
為陣列去別名:typedef int A[6];