2015-12-21 75 views
-3
struct line { 
    char* string; 
    struct line* next; 
}; 

有人可以請解釋發生了什麼嗎? 例:不知道發生了什麼 - C

  • 創建結構 「線」

  • 這種結構具有char變量 「字符串」 - >請告訴我與 「*」 ??

  • 在這個結構中,我們創建一個叫做「line *」的新函數 - >什麼是「*」?

  • 新的結構有一個領域的「下一個」

+3

。 – haccks

+1

退後幾步。結構應該放在後面的章節中,而不是任何關於C的書中的指針。 – kay

+0

struct定義了**鏈接列表**的節點。 '*'表示結構字段是一個指針。所以'char * string;'是指向節點初始化的數據的指針。並且'struct line * next;'指向下一個節點(相同類型),它是到列表中下一條記錄的鏈接。鏈中的最後一條記錄在此字段中將具有「NULL」。 –

回答

1
struct line { // create structure 
char* string; // here * represent pointer and this line creates character pointer named string 
struct line* next; // create pointer to structure named next 
}; 

請參閱本教程 http://www.cprogramming.com/tutorial/c/lesson6.html

這裏line是結構。

它裏面所創建的指針line和指針的名字是閱讀有關指針next

+0

謝謝!但是「int fun(struct line * list){...}」 - >表示這個函數需要一個類型行的指針(稱爲列表)? –

+0

這裏'fun'將指針指向結構體(稱爲列表)作爲參數 –

4

基本上,你的結構stringline不是數據項,但指針到實際的數據項都位於內存中的位置。

您可以通過tutorial on pointers in C瞭解更多。

相關問題