Types of Data Types (Data Handling Part 2)
In this tutorial we will discuss the type of data type, there are five fundamental data types in C++: char, int, float, double, and void. All the other data types are based on these data types and those data types are known as derived data types.
Types of Data Type
Fundamental Data Types
Those data types that are not composed of other data types are known are fundamental data types. We use variables to store data of specific data types, the variable is a named space to hold the value of a certain data type. Syntax to declare a variable for any fundamental data type is :
There are five fundamental data types in the C++ programming language :
1. int Data Type (for Integers)
- It is used to represent integers, Integers are the whole number such as 5, 23, -256, etc.
- It can not have a fractional value.
- It can be negative or positive but only in this range -2147483648 to 2147483647.
- Its size is usually 4 bytes.
int num =5000;
2. char Data Type (for characters)
- char can store any character from the C++ basic character set.
- Its size is 1 byte.
- char in C++ is usually stored in a single quote ' '.
- In C++ each character has an equivalent integer code which is known as ASCII code.
- ASCII code stores number codes for 256 known characters: letter, digits, symbols, nano graphic characters, etc.
char ch = 'A' ;
3. float and double Data Type (for floating-point numbers)
- A number having a fractional value is known as a floating-point number, for example, 2.893 is a floating-point number.
- Floating-point variables are used to represent values like distance, area, temperature, etc.
- The size of float data type is 4 bytes and the size of double data type is 8 bytes.
doublehas two times the precision of float.
- The range of float is 1.2E-38 to 3.4E+38 and the range of double is 2.3E-308 to 1.7E+308.
- Floating point numbers can also be written as exponent notation. For example, 147.9101 can be written as 1.479101E02.
float pi = 3.14; double area = 123.23243;
4. bool Data Type ( true or false)
- The bool data type is used to represent "true" or "false".
- The default numeric value of "true" is 1.
- The default numeric value of "false" is 0.
- It is mostly used in conditional statements.
bool right = true; bool wrong = false;
5. void Data Type ( for an empty set of values and non-returning functions)
- The simple meaning of void is "null" or "no data".
- The void data type is used to specify an empty set of values.
- It is used as a return type of function which does not return any value.
- We can not declare objects for a void data type.
Derived Data Types
The data types which are derived using fundamental data types are known as Derived Data Types. for example Array, Pointers, References, Constants, etc.
We will learn more about derived data types in future tutorials.
Now, this the end of this tutorial we will learn about the Data Type Modifier in the next tutorial.