Sams Teach Yourself C in 21 Days

(singke) #1
Answers 859

F



  1. 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.

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

  3. 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.

  4. 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.

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

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

  7. An uninitialized local variable isn’t automatically initialized; it could contain any-
    thing. You should never use an uninitialized local variable.

  8. 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.

  9. 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;

  10. The externkeyword is used as a storage-class modifier. It indicates that the vari-
    able has been declared somewhere else in the program.

  11. 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;


  1. 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

Free download pdf