Sams Teach Yourself C in 21 Days

(singke) #1
Answers for Day 7

Quiz


  1. There are two differences between puts()andprintf():
    printf()can print variable parameters.
    puts()automatically adds a newline character to the end of the string it prints.

  2. You should include the stdio.h header file when using printf().

  3. a.\prints a backslash.
    b.\bprints a backspace.
    c.\nprints a newline.
    d.\tprints a tab.
    e.\a(for “alert”) sounds the beep.

  4. a.%sfor a character string
    b.%dfor a signed decimal integer
    c.%ffor a decimal floating-point number

  5. a.bprints the literal character b.
    b.\bprints a backspace character.
    c.\looks at the next character to determine an escape character (see Table 7.1).
    d.\prints a single backslash.


Exercises

1.puts()automatically adds the newline; printf()does not. The code is as follows:
printf( “\n” );
puts( “ “ );


  1. The code is as follows:
    char c1, c2;
    int d1;
    scanf( “%c %ud %c”, &c1, &d1, &c2 );

  2. Your answer might vary:
    #include <stdio.h>
    int x;
    int main( void )
    {
    puts( “Enter an integer value” );


842 Appendix F

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

Free download pdf