C++ Data Types To Perform Different Operations

How many types of Data Types are available in C++

There are four following data types in C++.
1.     Integer
2.     Character
3.     Boolean
4.     Floating Point
5.     Double Floating Point
Each type has some subtype for different operations. The selection of the suitable type and its subtype depends on the requirement.

Integer Data Type

Integer data is a numeric value with no decimal point or fraction. It includes both negative and positive values. The minus (-) Sign is used for negative values. If no sign is used it means that it is a positive integer value.

Types of int data type

Following are the types of int data types in C++ (C plus).

Data Type

Size in Bytes

Description

size of int
2
Ranges from -32,768 to 32,767
Size of Short int
2
Ranges from -32,768 to 32,767
Size of Unsigned int
2
Ranges from 0 to 65,535
Size Long int
4
Ranges from -2,147,483,648 to 2,147,483,647
Size of Unsigned long int
4
Ranges from 0 to 4,294,967,295

Example

Here are some examples of integer data types 525, 1024,1 and -23, -222, etc.

Int data type

Int type is used to store integer values. It takes 2 bytes in memory depending on the computer and the compiler being used. Its range is from -32768 to 32767.

Code

#include<iostream>
using namespace std;
//programingitians Integer type program
int main()
{
            int a;
            cout<<"Enter a number"<<endl;
            cin>>a;
            return 0;
}

Integer data type program output

C++ Data Types To Perform Different Operations
Integer or Int data type output

Short int

The short int type is used to store integer values. It takes 2 bytes in memory.it ranges from -32768 to 32767.

Unsigned int

The unsigned int type is used to store positive integer values.it takes 2 bytes in memory.it Ranges from 0 to 65,535.

Long int

The long int type is used to store long integer values. it takes 4 bytes in memory. It Ranges from -2,147,483,648 to 2,147,483,647.

Unsigned long int

The unsigned long int type is used to store large integer values. It takes 4 bytes in the memory. It Ranges from 0 to 4,294,967,295.

Real Or Float data type

The float type is used to store real values or values with a decimal fraction. It takes 4 bytes in the memory. It provides the accuracy of 15 decimal places.

Float data type

Bytes

Description

Size Double float type
8
1.7X10-308  to 1.7X10+308
Size Long Double data type
10
1.7X10-4932 to 1.7X10+4932

 Code

#include<iostream>
using namespace std;
//programingitians Float type program
int main()
{
            float a;
            cout<<"Enter a number with decimal"<<endl;
            cin>>a;
            return 0;
}

Float program output

C++ Data Types To Perform Different Operations
Float Data type Program Output

Double Float

The double float type is used to store large float values. It takes 8 bytes to store values in the memory. Its range is from 1.7X10-308  to 1.7X10+308.

Long Double Float

The double float type is used to store large float values. It takes 8 bytes to store values in the memory. Its range is from 1.7X10-4932 to 1.7X10+4932.

Character Data type

Char type is used to store character values. It takes 1 byte in the memory.it is used to represent a letter and some special symbols.
Characters are given in single quotes.

Code

#include<iostream>
using namespace std;
//programingitians Char or character type program
int main()
{
     char a;
            cout<<"Enter a number Character"<<endl;
            cin>>a;
            return 0;
}

Char Or Character type Program Output

C++ Data Types To Perform Different Operations
Char Or Character Data Type

String data type

String type is used to store a phrase of text or a paragraph.

Code

#include<iostream>
using namespace std;
//programingitians string type program
int main()
{
     string a;
            cout<<"Enter a number string"<<endl;
            cin>>a;
            return 0;
}

String type program output

C++ Data Types To Perform Different Operations
String data type output
Post a Comment (0)
Previous Post Next Post