Sams Teach Yourself C in 21 Days

(singke) #1
Understanding Variable Scope 303

12



  1. What does the following program print? Don’t run the program—try to figure it
    out by reading the code.
    #include <stdio.h>
    void print_letter2(void); / function prototype /


int ctr;
char letter1 = ‘X’;
char letter2 = ‘=’;
int main( void )
{
for( ctr = 0; ctr < 10; ctr++ )
{
printf( “%c”, letter1 );
print_letter2();
}
return 0;
}
void print_letter2(void)
{
for( ctr = 0; ctr < 2; ctr++ )
printf( “%c”, letter2 );
}
10.BUG BUSTER:Will the preceding program run? If not, what’s the problem?
Rewrite it so that it is correct.

19 448201x-CH12 8/13/02 11:17 AM Page 303

Free download pdf