[ fromfile: scopestorage-questions.xml id: questions-scopestorage ]
What is a scope? What kinds of "things" have a scope?
Scope is a region of code where an identifier can be used. All identifiers have scope.
What is a storage class? What kinds of "things" have a storage class?
Storage class is an area of memory. objects, temporary expresisons, variables, all have a storage class.
When are static
objects initialized? Be sure to consider both globals and block scope objects.
For globals, when the object module (library or executable) is loaded. For block-scope locals, they are initialized when the code is executed for the first time.
How does const
act as a scope modifier?
It turns global scope objects into file-scope objects (not exported by the linker). They are local to the source module only.
What does extern
mean?
adding the keyword extern
turns a definition into an external declaration. No storage is allocated, no initial value can be assigned. The object must be defined in another module. extern
tells the compiler let the linker figure out where the definition is.
The keyword static
has many meanings depending on where it is used.
Explain how static
can be used as a scope modifier.
It changes a global name to file-scope, preventing it from being exported to the linker.
Explain how static
can be used as a storage-class modifier.
When applied to a block scope object, it changes the storage class from stack to static.
Give another use for the keyword static
.
What is the storage class of an object defined in a namespace
?
What is special about a pointer to an object declared using the keyword register
?
What is the difference between a class
and a namespace
?
What must you do if you want to declare an object in the header file of a namespace
without defining it?
Generated: 2012-03-02 | © 2012 Alan Ezust and Paul Ezust. |