Chapter 3

1: Which data type would you use for each of the following kinds of data?
  1. The population of East Simpleton

  2. The cost of a movie on DVD

  3. The most common letter in this chapter

  4. The number of times that the letter occurs in this chapter

A1:
  1. int, possibly short or unsigned or unsigned short; population is a whole number.

  2. float; it's unlikely the cost will be an exact integer. (You could use double but don't really need the extra precision.)

  3. char.

  4. int, possibly unsigned.

2: Why would you use a type long variable instead of type int?
A2: One reason is that long may accommodate larger numbers than int on your system; another reason is that if you do need to handle larger values, you improve portability by using a type guaranteed to be at least 32 bits ...

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.