Answers 859
F
- 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. - Defining a variable in a function makes it local; defining a variable outside of any
function makes it external. - 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. - An automatic variable is initialized every time the function is called. A static vari-
able 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 any-
thing. You should never use an uninitialized local variable. - Because the variable countis now local to the block, the printf()no longer has
access to a variable called count. The compiler gives you an error. - If the value needs to be remembered, it should be declared as static. For example,
if the variable were called vari, the declaration would be
static int vari; - The externkeyword is used as a storage-class modifier. It indicates that the vari-
able has been declared somewhere else in the program. - The statickeyword 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.
Exercises
1.register int x = 0;
- The code is as follows:
/ Illustrates variable scope. /
#include <stdio.h>
void print_value(int x);
int main( void )
{
int x = 999;
printf(“%d”, x);
print_value( x );
49 448201x-APP F 8/13/02 11:22 AM Page 859