c++~!~!

2007-03-25 10:08 am
scope rule 系咩ar?
更新1:

and how to use it?

回答 (1)

2007-03-25 10:24 pm
✔ 最佳答案
Scope defines how and where variables live in your program.
The simple ones are local and global variables, there is also static and extern.

- local lives within block level, e.g. within a pair of {}. Once the variable goes out of scope (closing braces), nobody can reference it. This is the most common use of variables.
- global is the opposite, it remains visible throughout the same program file. All methods within the same same file can reference global variables.
- static lives before a class object is instantiated. usage: ClassA.variable = 1; It is generally used for storing static values such as constants (values that never change) so references to the values is easy. Math.PI is a good example.
- extern is a hint to the program saying that the variable lives in the program, may not be in the same file.


收錄日期: 2021-04-23 21:04:33
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20070325000051KK00497

檢視 Wayback Machine 備份