There are basically three C++ integer types:

- A short is at least 16 bits.
- An int is at least as big as short.
- A long is at least 32 bits and at least as big as int.

There is an easy way to find out the exact size of your system’s integers. You can simply print symbolic constants provided by <climits> (or <limits.h> for older implementations) in a program. You can also use **sizeof** on a type to see how big it is in bytes. For example, sizeof(int) gives you 4 and sizeof(short) gives you 2 on most systems.

Now that we understand that, let’s turn our attention to the potential traps we could fall into if we are not careful enough. I have the following declarations:

int john=0; unsigned int cheryl=0;I deduct one from

john--; cheryl--; cout<<"John: " <<john<<" Cheryl: "<<cheryl;I got

john=INT_MAX; cheryl= INT_MAX;Add one to

john++; cheryl++; cout<<"John: " <<john<<" Cheryl: "<<cheryl;I got

Your intuition probably tells you that –2147483648 is the minimum value of

As we can see, when you subtract one from the minimum value of unsigned int, you get the maximum value of unsigned int; when you add one to the maximum value of int, you get the minimum value of int.

The overflow and underflow behavior can be depicted as a circle: if you move past the limit of a type, you get the value at the other extreme of the range.

You can also try the following code in your program:

cout<<INT_MAX<<endl; cout<<INT_MAX*2<<endl; /* print out –2 */Try to figure out why the output is –2. You can use a narrower analogous situation such as use 5 as the maximum value and –6 as the minimum value.

Next we’ll look at short-circuit evaluation and how we can use it effectively!

◀ Assignment Operator Between Two Structure Instances▶ Short-Circuit Evaluation