What is the Data Types in C++ ? with free Explanation

What is the Data Types in C++ ?

For Doing Programming we can use data as a row material which is store in a variable.datatype is the type of value which the variable can store has to be specified by the programmer.

Basic Data Types

These types of Data is also called a inbuild data type or primary data type. We can use these data type with different arguments like – short, long, signed, unsigned etc. C++ have following inbuild data types.

  1. int : Which is ysed to store integer values like 4, 78, 568 etc.
  2. float : Which is used to store decimal value like 4.0, 7.8 etc.
  3. char : Which is used to store characters like ‘a’, ‘7’ etc.
  4. Bool : it is used to store Boolean Value either 0 or 1.
  5. void : it signifies absence of information.

1. Integer Data Type

Integer data types are used to store integer values like 3, 890, 789 etc. We can store an integer value by declaring a variable of type integer. For using type, type keyword int followed by the name of the variable. We can give any name to a variable but cannot use a keyword as a variable. For example, the statement:

int s;

it declares that s is a variable of type int. We can assign it an integer value. In order to assign value along with declaration use the assignment operator (=).

int s = 10;

assign values 10 to variable s.

There are three types of integer variable in C++, short, int and long int. All of them store values of type integer but the size of values they can store increases from short to long int. This is because of the size occupied by them in memory of the computer. If the size of the memory is large then, more the value they can hold.

Data TypeMemory SizeMinimum RangeMaximum Range
Short int 1-128127
Signed int 2-3276832767
Unsigned int3065535
Long int4-21474836482147483647

Variables can be signed or unsigned depending they store only positive value or both positive and negative values.

2. Float Data Type

To store decimal values, we use float data type. Floating point data types comes in three sizes, namely float, double, and long double. The difference between these three types is in the length of value and amount of precision which they can take and it increases from float to long double. like: –

Data TypeMemory SizeMinimu RangeMaximu RangeDigits of Precision
Float 43.4e-383.4e+386
Double 81.7e-3081.7e+30815
Long Double 103.4e-49323.4e+493218

For example, statement

float age = 2.34;

declares a variable age which is of type float and has the initial value 2.34

3. Character Data Type

A variable of type char stores one character. It size of a variable of type char is typically 1 byte. The statement

char name = 'a';

declares a variable of type char can hold only one character and has the initial values as character a. Note that value has to be under single quotes.

Data Type NameMemory Size in BytesMinimum Range Maximum Range
Signed Char1-128127
Unsigned Char10255

4. Boolean

A variable of type Bool can store either value true or false and is mostly used in comparisons and logical operations. When it convert int integer, true is any non zero value and false corresponds to zero.

5. Void

The void data type is an uncompleted type that can never be completed. Void is used to declare function or data with no associated datatype.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top