- Home
- Interview Questions
- C Programming
An automatic variable is initialized every time the function is called. A static variable is initialized only the first time the function is called.
False. When declaring register variables, you’re making a request. There is no guarantee that the compiler will honor the request.
An uninitialized global variable is automatically initialized to 0; however, it’s best to initialize variables explicitly.
An uninitialized local variable isn’t automatically initialized; it could contain anything. You should never use an uninitialized local variable.
The extern keyword is used as a storage-class modifier. It indicates that the variable has been declared somewhere else in the program.
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.
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.
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.
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.
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.