2012-08-07 37 views

回答

1

typedef不是全局變量,它只是另一種類型的別名。當我將它們傳遞出去時,我通常會將它們用於函數指針,因爲每次寫出它們都很煩人。

typedef int (*function)(int, int);

我還用它來定義一個結構,聯合或枚舉作爲一種

typedef struct { 
    int x; 
    int y; 
    int z; 
} Point; 
0

這可以幫助你。在這裏發佈的代碼中,出現錯誤。側面主要功能沒有語句。 getch和return語句應該在main函數中。我覺得你的代碼應該是這樣的。

#include <stdio.h> 
typedef int arrChoice; /* arrChoice is alias to int */ 
arrChoice a[10] ;/* array a is a global variable of integers*/ 
int main() 
{ 
getch(); 
return 0; 
} 

請注意類型定義的目的是爲了分配選擇的名稱以現有的類型(整型,浮點,雙,等)。以下聲明是相似的。

typedef arrChoice[10] is similar to typedef int[10]; 

當您嘗試參考arrChoice,那麼你會得到一個錯誤信息

expected expression before 'arrChoice'.