Creating New Types

You've already learned about the C++ built-in types, including int (integers) and char (characters). The type of a variable tells you quite a bit about it. For example, if you declare Height and Width to be unsigned short integers, you know that each one can hold a number between 0 and 65,535 (assuming an unsigned short integer is 2 bytes).

In addition to telling you the size, the type tells you the capabilities of the variable. For example, short integers can be added together. Thus, just by declaring Height and Width to be unsigned short integers, you know that it is possible to add Height to Width and to assign that number to another number.

The type of these variables tells you

  • Their size in memory

  • What information they ...

Get Sams Teach Yourself C++ in 24 Hours, Third 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.