Chapter 4

1: Run Listing 4.1 again, but this time give your first and last name when it asks you for your first name. What happens? Why?
A1: The program malfunctions. The first scanf() statement reads just your first name, leaving your last name untouched but still stored in the input “buffer.” (This buffer is just a temporary storage area used to store the input.) When the next scanf() statement comes along looking for your weight, it picks up where the last reading attempt ended, and tries to read your last name as your weight. This frustrates scanf(). On the other hand, if you respond to the name request with something like Lasha 144, it uses 144 as your weight, even though you typed it before your weight was requested.
2: Assuming that each ...

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.