Chapter 3

1: Why does C++ have more than one integer type?
A1: Having more than one integer type lets you choose the type best suited to a particular need. For example, you could use short to conserve space, long to guarantee storage capacity, or find that a particular type speeds up a particular calculation.
2: Define the following:
  1. A short integer with the value 80

  2. An unsigned int integer with the value 42110

  3. An integer with the value 3000000000

A2:
short rbis = 80;            // or short int rbis = 80;
unsigned int q = 42110;     // or unsigned q = 42110;
unsigned long ants = 3000000000;

Note

Don't count on int being large enough to hold 3000000000.

3: What safeguards ...

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.