#include <stdio.h>
#include <conio.h>
typedef arrChoice[10] /*is this a global variable?*/
int main() {};
getch();
return 0;
}
它還沒有完成,但這就是我的意思。就像「typedef int arrChoice [5];」一個全局變量?
#include <stdio.h>
#include <conio.h>
typedef arrChoice[10] /*is this a global variable?*/
int main() {};
getch();
return 0;
}
它還沒有完成,但這就是我的意思。就像「typedef int arrChoice [5];」一個全局變量?
typedef不是全局變量,它只是另一種類型的別名。當我將它們傳遞出去時,我通常會將它們用於函數指針,因爲每次寫出它們都很煩人。
typedef int (*function)(int, int);
我還用它來定義一個結構,聯合或枚舉作爲一種
typedef struct {
int x;
int y;
int z;
} Point;
typedef聲明新類型不可變。
這可以幫助你。在這裏發佈的代碼中,出現錯誤。側面主要功能沒有語句。 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'.
SHOW你的代碼! – tbert 2012-08-07 03:48:49
typedef不是一個變量,它只是做它所說的......定義一個類型。 – borrrden 2012-08-07 03:49:29