自動 (函式範圍) 變數
在函式內宣告的變數只能在該函式的範圍內使用。
// LNK2019_AV.cpp
// compile with: /c
void test(void);
static int lnktest3 = 3;
int lnktest4 = 4;
int main() {
static int lnktest1 = 1;
int lnktest2 = 2;
test();
}
然後
// LNK2019_AV_2.cpp
// compile with: LNK2019_AV.cpp
// LNK2019 expected
extern int lnktest1;
extern int lnktest2;
extern int lnktest3;
extern int lnktest4;
void test(void) {
int i = 0;
i = lnktest1;
i = lnktest2;
i = lnktest3;
i = lnktest4; // OK
}
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應