雖然我讀的Use of 'extern' keyword while defining the variableextern int a之間的區別; extern int a = 42;
一個用戶的答案回答了這些方式
extern int a; // not a definition
extern int a = 42; // definition
我期待雙方都沒有定義,但聲明。我在想這兩個聲明都說變量是在函數外部定義的,我們必須使用extern關鍵字來使用它。這是他的錯誤還是它真的是一個定義? 我知道
extern int a; // variable is already defined but its outside the function
extern int a=42 ; //I guess a variable is assigned a value but not a definition
但這些聲明
extern int a = 42; // user said its a definition and now i got confused
請清除我這些。
的聲明規定外main()函數內聲明的價值正在討論的鏈接問題都假定爲文件作用域聲明,而不是函數作用域。 –