Home
91.
How big is a union?

Because each member in a union is stored in the same memory location, the amount of room required to store the union is equal to that of its largest member.

92.
How is a structure different from an array?

The data items in an array must all be of the same type. A structure can contain data items of different types.

93.
What is the structure member operator, and what purpose does it serve?

The structure member operator is a period. It is used to access members of a structure.

94.
What is the difference between a structure tag and a structure instance?

A structure tag is tied to a template of a structure and is not an actual variable. A structure instance is an allocated structure that can hold data.

95.
If global variables can be used anywhere in the program, why not make all variables global?

As your programs get bigger they will contain more and more variables. Global variables take up memory as long as the program is running, whereas automatic local variables take up memory only while the function they are defined in is executing. Hence, use of local variables reduces memory usage. More important, however, is that the use of local variables greatly decreases the chance of unwanted interactions between different parts of the program, hence lessening program bugs and following the principles of structured programming.

96.
Can I declare a local variable and a global variable that have the same name, as long as they have different variable types?

Yes. When you declare a local variable with the same name as a global variable, it is a completely different variable. This means that you can make it whatever type you want. You should be careful, however, when declaring global and local variables that have the same name. Some programmers prefix all global variable names with 'g" (for example, gCount instead of Count). This makes it clear in the source code which variables are global and which are local.

97.
What does scope refer to?

The scope of a variable refers to the extent to which different parts of a program have access to the variable, or where the variable is visible.

98.
What is the most important difference between local storage class and external storage class?

A variable with local storage class is visible only in the function where it is defined. A variable with external storage class is visible throughout the program.

99.
How does the location of a variable definition affect its storage class?

Defining a variable in a function makes it local; defining a variable outside of any function makes it external.

100.
When defining a local variable, what are the two options for the variable's lifetime?

Automatic (the default) or static. An automatic variable is created each time the function is called and is destroyed when the function ends. A static local variable persists and retains its value between calls to the function.