struct型別宣告的疑問

2022-07-18 17:48:09 字數 503 閱讀 8640

如果struct型別的宣告放在函式體內,比如下面這個程式:

#include

#define n 5

int main()

;struct student stu[n],*s=stu;

s=input(stu);

return 0;

}struct student *input(struct student *p)

編譯時在引用input函式行出現錯誤:「student *型別的實參與student *型別的形參不相容「,

這個錯誤的原因可解釋為struct型別的宣告在input函式的宣告之後,函式無法對實參、形參進行匹配。

但如果把struct型別宣告放在input函式宣告之前(仍然在main函式內),則會在input函式宣告行出現錯誤:

」使用區域性型別宣告的 函式「input」必須在此翻譯單元中定義「。

這個錯誤出現的原因就無法解釋了。

當然,struct型別的宣告放在主函式之前就沒有任何錯誤。

Struct 簡單的宣告物件方式

在 php 裡面,很多時候我們會用到 hash 來傳遞變數,像是 something abc def 之類的方式,或許這是乙個在效率上面很好的實做方式,但是總是.怪怪的,不是那麼的優雅。在 rails 裡面,難免會有 controller 傳遞變數到 view 裡面的時候,這個時候通常是用 flas...

struct結構體的多種宣告方式

在宣告結構體時,必須列出它包含的所有成員 語法結構struct tag variable list struct x 這個宣告建立名為x的變數,它包含四個成員。struct y 20 z 這個宣告建立名為y和z的指標變數,y是乙個陣列,它包含20個結構。z是乙個指標,指向這型別的結構。這兩個宣告是截...

關於OleVariant型別的疑問

關於olevariant型別的疑問?vcl元件開發及應用 我在remotedatamodule中建立了乙個這樣的過程 類似於策略模式中 上下文 類 申明 procedure strategytrans var stgy olevariant safecall 實現 procedure tsvqueu...