Home
101.
Your program can initialize both automatic and static local variables when they are defined. When do the initializations take place?

An automatic variable is initialized every time the function is called. A static variable is initialized only the first time the function is called.

102.
True or False: A register variable will always be placed in a register.

False. When declaring register variables, you’re making a request. There is no guarantee that the compiler will honor the request.

103.
What value does an uninitialized global variable contain?

An uninitialized global variable is automatically initialized to 0; however, it’s best to initialize variables explicitly.

104.
What value does an uninitialized local variable contain?

An uninitialized local variable isn’t automatically initialized; it could contain anything. You should never use an uninitialized local variable.

105.
What does the extern keyword do?

The extern keyword is used as a storage-class modifier. It indicates that the variable has been declared somewhere else in the program.

106.
What does the static keyword do?

The static keyword is used as a storage-class modifier. It tells the compiler to retain the value of a variable or function for the duration of a program. Within a function, the variable keeps its value between function calls.

107.
Is it better to use a switch statement or a nested loop?

If you're checking a variable that can take on more than two values, the switch statement is almost always better. The resulting code is easier to read, too. If you're checking a true/false condition, go with an if statement.

108.
Why should I avoid a goto statement?

When you first see a goto statement, it's easy to believe that it could be useful. However, goto can cause you more problems than it fixes. A goto statement is an unstructured command that takes you to another point in a program. Many debuggers (software that helps you trace program problems) can't interrogate a goto properly. goto statements also lead to spaghetti code—code that goes all over the place.

109.
Is it good to use the system() function to execute system functions?

The system() function might appear to be an easy way to do such things as list the files in a directory, but you should be cautious. Most operating system commands are specific to a particular operating system. If you use a system() call, your code probably won’t be portable. If you want to run another program (not an operating system command), you shouldn’t have portability problems.

110.
What’s the difference between the break statement and the continue statement?

When a break statement is encountered, execution immediately exits the for, do...while, or while loop that contains the break. When a continue statement is encountered, the next iteration of the enclosing loop begins immediately.