Sams Teach Yourself C in 21 Days

(singke) #1
Answers 863

F


return 0;
}
void print_letter2(void)
{
char letter2 = ‘=’;
int ctr; /* this is a local variable */
/* it is different from ctr in main() */
for( ctr = 0; ctr < 2; ctr++ )
printf( “%c”, letter2 );
}

Answers for Day 13

Quiz


  1. Never. (Unless you are very careful.)

  2. When a breakstatement is encountered, execution immediately exits the for,
    do...while,orwhileloop that contains the break. When a continuestatement is
    encountered, the next iteration of the enclosing loop begins immediately.

  3. An infinite loop executes forever. You create one by writing a for,do...while,or
    whileloop with a test condition that is always true.

  4. Execution terminates when the program reaches the end of main()or the exit()
    function is called.

  5. The expression in a switchstatement can evaluate to a long,int,orcharvalue.

  6. The defaultstatement is a case in a switchstatement. When the expression in the
    switchstatement evaluates to a value that doesn’t have a matching case, control
    goes to the default case.

  7. The exit()function causes the program to end. A value can be passed to the
    exit()function. This value is returned to the operating system.

  8. The system()function executes a command at the operating system level.


Exercises

1.continue;
2.break;


  1. For a DOS system, the answer would be
    system(“dir”);

  2. This code fragment is correct. You don’t need a breakstatement after the printf()
    for‘N’, because the switchstatement ends anyway.


49 448201x-APP F 8/13/02 11:22 AM Page 863

Free download pdf