The data type defines a set of values and a set of operation on those values. The computer manipulates various types of data. This data is given to the computer as input. The data is processed according to the program instructions to produce outputs. As the computer memory is organized in bytes, and the memory for each variable is associated with its data type.
The data that is entered or the information and its data type are defined before designing the actual program that is used to process the data. The type of each data value is identified at the beginning of program design.
C program may need to process different types of data. Each data type require amount of memory. C++ programming language provides the following data types:
|int||Stores numeric values|
|float||Stores real values|
|double||Stores large real values|
|char||Stores character values|
|bool||Stores either true or false|
|void||It is value less. Void means “nothing”|
C++ programming language provides the following ways to use data types:
- Standard data types/built in data types
- User defined data types
A data type that is predefined in the language is called standard data type or built in data type. Some examples of standard data type are int, float, long, bool and char etc.
The C++ programming language also allows the user to define his own data types and they are called user defined data types.
Integer data is the numeric value with no decimal point or fraction. It includes both positive and negative values. The minus sign – is used to indicate the negative value. If no sign is used, the value is considered to be positive by default.
Some of examples of integer type data are 15, -2, etc.
Types of integer data
The C++ programming language provides different types of integer data. These are as follows:
- Int (it is used to store whole number values)
- Short int (it takes two bytes in memory)
- unsigned int (it stores only positive integer values)
- long int (it stores larger values)
- Unsigned long int (it is used to store larger positive values)
|Data type||Size in Bytes||Ranges|
|int||2||-32768 to 32767|
|short||2||-32768 to 32767|
|Unsigned int||2||0 to 65535|
|long||4||-2147483648 to 2147483647|
|Unsigned long||4||0 to 4294967295|
This type of data is a numeric value with decimal point or fraction. It is also called real type data. It includes both positive and negative values.
10.5, -3.4, etc
Types of floating point
C++ programming language provides different types of floating point data. These are as follows:
- Long double
|Data type||Size in Bytes||Description|
|float||4||3.4*10^-38 to 3.4*10^38|
|double||8||1.7*10^-308 to 1.7*10^308|
|Long double||10||1.7 *10^-4932 to 1.7*10^4932|
Character data type
This data type is used to store character value. It takes 1 byte in memory. It is used to represent letters, number or punctuation marks and a few other symbols.
These types of values are normally given in single quotes.
‘a’, ‘5’, ‘#’, etc
Boolean data type
The bool data type is used to store either true or false.
Void data type
Void data type is used in functions that do not have any return value this will be discussed on later chapters.
Data type of expressions
The data type of an expression depends on the types of operand in the expression. For example the result of an expression is int if both the operands are integer.