FUNDAMENTAL DATA TYPES

The sort of information that a variable can hold is determined by its data type. All data and variables in your program must be of some defined type. C++ provides you with a range of fundamental data types, specified by particular keywords. Fundamental data types are so called because they store values of types that represent fundamental data in your computer, essentially numerical values, which also includes characters because every character is represented by a unique numerical character code. You have already seen the keyword int for defining integer variables.

The fundamental types fall into three categories:

  • Types that store integers
  • Types that store non-integral values, called floating-point types
  • The void type that specifies an empty set of values or no type

Integer Variables

Integer variables are variables that can have only values that are whole numbers. The number of players in a football team is an integer, at least at the beginning of the game. You already know that you can declare integer variables using the keyword int. Variables of type int occupy 4 bytes in memory and can store both positive and negative integer values. The upper and lower limits for the values of a variable of type int correspond to the maximum and minimum signed binary numbers, which can be represented by 32 bits. The upper limit for a variable of type int is 231-1, which is 2,147,483,647, and the lower limit is -(231), which is −2,147,483,648. Here’s an example of defining ...

Get Ivor Horton's Beginning Visual C++ 2012 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.