O'Reilly logo

C Primer Plus, Fourth Edition by Stephen Prata

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required