一.
typedef定義型別的別名,和引用相似,引用是變數或者物件的別名
typedef prefix suffix; //程式中用後者表示前者
#define m_prefix m_suffix; //程式中用前者表示後者
這是關於這兩者我最直接膚淺的理解。
二.typedef struct 和 struct定義結構體也更好理解了。
在c中定義乙個結構體型別要用typedef:
(1)
由此看來stu實際上是struct student的別名:stu==struct studenttypedef struct student
stu;
typedef struct 結構名
結構別名;
於是在宣告變數的時候就可以寫:stu stu1;(如果沒有typedef就必須用struct student stu1;來宣告)
(2)如果沒有student
宣告變數的時候要寫: stu stu1; //stu成了唯一乙個結構體型別而不是結構體別名。typedef struct
stu;
三.c++中定義的結構體
(1)結構體型別student
宣告變數時直接:stu2就直接是乙個student的變數了struct student
stu2;
(2)
這裡stu2是乙個結構體型別=struct studenttypedef struct student
stu2;
typedef與 define 的區別
一 typedef的用法 typedef常用來定義乙個識別符號及關鍵字的別名,它是語言編譯過程的一部分,但它並不實際分配記憶體空間,例項像 typedef int int typedef int array 10 typedef int pint typedef可以增強程式的可讀性,以及識別符號的靈...
typedef與 define 的區別
typedef與 define 的區別 一 typedef的用法 typedef常用來定義乙個識別符號及關鍵字的別名,它是語言編譯過程的一部分,但它並不實際分配記憶體空間,例項像 typedef int int typedef int array 10 typedef int pint typede...
typedef與 define的區別
typedef與 define的區別 從以上的概念便也能基本清楚,typedef只是為了增加可讀性而為識別符號另起的新名稱 僅僅只是個別名 而 define 原本在c中是為了定義常量,到了c const enum inline的出現使它也漸漸成為了起別名的工具。有時很容易搞不清楚與typedef兩者...