Chapter 8

1: putchar(getchar()) is a valid expression; what does it do? Is getchar(putchar()) also valid?
A1: The statement putchar(getchar()); causes the program to read the next input character and to print it; the return value from getchar() is the argument to putchar(). No, getchar(putchar()) is invalid because getchar() doesn't use an argument and putchar() needs one.
2: What would each of the following statements accomplish?
  1. putchar('H');

  2. putchar('\007');

  3. putchar('\n');

  4. putchar('\b');

A2:
  1. Display the H character.

  2. Sound the alert if the system uses ASCII.

  3. Move the cursor to the beginning of the next line.

  4. Backspace.

3: Suppose you have a program count that counts the characters in its input. Devise a command that counts the number of characters in ...

Get C Primer Plus, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.