English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

之前對 file-scope variables 與 global variables 的差別不是很清楚,直到找到某一位大大發問的文章…
http://tw.knowledge.yahoo.com/question/?qid=1305100613273

而熱心回答的一位大大說「檔案範圍是指你的宣告並不在任何函式及class/struct和’{‘與’}’之間. 例如global(全區域)變數.」 這也就是說global variables是file-scope的一種囉?兩者差別有哪?那在file-scope variables還有另外哪幾種?

另外何謂 non-local variables?是指除 local variables之外的所有varialbes都屬這類嗎?

希望原回答者出來說一下…謝謝

2006-11-20 18:35:09 · 3 個解答 · 發問者 HA User 3 in 電腦與網際網路 程式設計

請龍大出馬吧~

2006-11-23 17:27:54 · update #1

3 個解答

引述自 http://www.thescripts.com/forum/thread557304.html
I would say there are 3 variable scopes, 4 if you include prototype-scope but that that doesn't seem useful to me
1. Program Scope: A variable that is declared outside of all code blocks and is not declared static is accessable from any part of the program (although use of an extern statement will be required).
2. File Scope: A variable that is declared outside of all code blocks and is declared static is accessable from any part of the file following the declaration.
3. Local or Block Scope: A variable declared inside a code block is only accessable within that block. The parameters of a function are consider to have local scope as if they had been decared inside the block enclosing the function body.
4. Prototype Scope: variables declared with-in a prototype have scope only up to the end of the prototype. meaning that for

2006-11-29 15:13:51 補充:
用中文來說,File Scope Variable就是宣告在括弧外的static變數。(Global Scope Variable加上static的宣告)其可見範圍只有在同一個file中。

2006-11-29 10:09:25 · answer #1 · answered by 光宇 4 · 0 0

真是太感謝了!

2006-11-21 07:06:52 · answer #2 · answered by HA User 3 · 0 0

龍大的回答,我不敢僭越。

在龍大回您前,這2篇給您參考一下。


http://tw.knowledge.yahoo.com/question/?qid=1206110907193

http://tw.knowledge.yahoo.com/question/?qid=1106110907456

2006-11-21 00:25:34 · answer #3 · answered by ? 7 · 0 0

fedest.com, questions and answers