2017-04-27 103 views
0

我無法解釋這個句子轉換成代碼: 一個函數調用max_occurences(),其具有一個指向結構的陣列出現作爲參數。指針傳遞到結構的數組的函數

我的理解是,他們的意思是這樣:

int max_occurences(struct occurrence *occurrences[]) 

但是這似乎是錯誤的。有人能幫助我理解它看起來像什麼嗎?我很困惑。

+2

那是一個指針數組結構(2級間接的)。你應該丟掉'*'或'[]'。您可能還想傳遞一個長度值來指示數組中有多少項。除非它終止於某種[哨兵價值](https://en.wikipedia.org/wiki/Sentinel_value)。 –

回答

1
int max_occurences(struct occurrence *occurrences[]) 

這裏的參數是指向struct occurrence的指針數組。

一個指向struct occurrence陣列將被宣佈爲 -

struct occurrence (*occurrences)[3]; 

所以你的說法應該是 -

int max_occurences(struct occurrence (*occurrences)[])