2012-02-21 107 views
0

我知道struct和struct之間的差異,前面帶有typedef關鍵字。參考是這樣的:typedef struct vs struct definitions不同類型的struct

struct myStruct{ 
    int one; 
    int two; 
}; 

VS

typedef struct{ 
    int one; 
    int two; 
}myStruct; 

但什麼是這兩種類型之間的差異:

struct point { 
    int x; 
    int y; 
}; 

VS

struct point { 
    int x; 
    int y; 
} my_point; 

還有一個:

typedef struct set_t{  
     int count; 
     void **values; 
    } *SetRef; 

這是什麼類型?

回答

2
struct point { int x; int y; }; 

聲明一個新型的struct point有兩個int成員xy

struct point { int x; int y; } my_point; 

這也聲明瞭一個新型struct point具有兩個int構件xy和此聲明struct point類型的對象my_point

2

my_pointstruct point類型的變量。

1

第一個聲明struct類型,而第二個聲明類型和實例my_point。換句話說,my_point不是一種類型,而是一個實際的struct point實例。

1

在第二個中,您還定義了一個類型爲struct point的varibale(名爲my_point)。

1

第一個只聲明結構。稍後您將不得不使用它來創建它的一個對象。 第二個同時聲明它的結構和對象。