C++ Data Types

  • Post author:
Download PDF
Advertisement

C++ Data Types

The C++ data types define a set of values and a set of operations on those values. The computer manipulates various types of data. The program is given to the program as input. The data is processed according to the program instructions and output is returned. The data and its type are defined before designing the actual program used to process the data. The type of each data value is identified at the beginning of the program design.

      A C++ program may need to process different types of data. Each data type requires a different amount of money. C++ language provides the following data types:

Data Type Description
bool Stores either value true or false.
char To store character values
int To store numeric values
float To store real values
double To store large real values
void Represents the absence of type.
wchar_t A wide-character type.

Integer Data Types

Integer data is a numeric value with no decimal point or fraction. It includes both positive and negative values. The minus sign- is used to indicate a negative value. If no sign is used, the value is positive by default.

Examples

            Some examples of integer values are 16,449, and -40, etc.

Types of Integers

           C++ different types of integer data. These are as follows:

Data Type

Size in Bytes

Description

int

2

Ranges from -32,768 to 32,767.
short

2

Ranges from -32768 to 32,767.
unsigned int

2

Ranges from 0 to 65,535.
long

4

 Range from -2,147,483,648 to 2,147,483,647.
unsigned long

4

Range from 0 to 4,294,967,295.
  1. int Data Type

The int data type is used to store integer values. It takes two or four bytes in memory depending on the computer and compiler being used. In MS-DOS, it takes two bytes and its range is from-32768 to 32767.

INT_MIN represents the smallest value that can be stored in int data type. INT_MAX represents the largest value that can be stored in int data type. Both INT_MIN and INT_MAX are found in limits.h file.

  1. short int Data Type

The short int data type is used to store integer values. It takes two bytes in memory. Its range is from -32768 to 32767.

SHRT_MIN represents the smallest value that can be stored in a short int data type. SHORT_MAX represents the largest value that can be stored in a short int data type. Both SHRT_MIN and SHRT_MAX are found in limits.h header file.

  1. Unsigned int Data Type

The unsigned int data type is used to store an only positive integer value. It takes two bytes in memory. Its range is from 0 to 65,535.

UINT_MAX represents the largest value that can be stored in unsigned int data type. It is found in limits.h header file.

  1. long int Data Type

The long int data type is used to store large, store large integer values. It takes four bytes in memory. Its range is from -2,147,483,648 to 2,147,483,647.

LONG_MIN represents the smallest value that can be stored in long int

Advertisement
data type.

LONG_MIN and LONG_MAX are found in limits.h header file.

  1. unsigned long int Data Type

The unsigned long int data type is used to store large positive integer values. It takes four bytes in memory. Its range is found 0 to 4,294,967,295.

ULONG_MAX represents the largest value that can be stored in unsigned long int data type. It is found in limits.h header file.

Real Data Types

Real data types are a numeric value with a decimal point or fraction. It is also called the floating-point number. It includes both positive and negative values. The minus sign is used to indicate a negative value. If no sign is used, the value is positive by default.

Example

Some examples of real values are 15.876 and -45.2 etc.

Types of real data

C++ provides different types of real data.

Data Type Size in Bytes Description
long double 10 1.7 x 10-4932 to 1.7 x 10+4932
Double 8 1.7 x 10-308 to 1.7 x 10+308
Float 4 3.4 x 10-38 to 3.4 x 10+38
  1. long double Data Type

The long double data type is used to store very large real values. It takes ten bytes in memory. Its range is from 1.7 x 10-4932 to 1.7 x 10+4932. It provides the accuracy of 19 decimal places.

LDBL_MIN represents the smallest value that can be stored in a long double data type.

LDBL_MAN represents the largest value that can be stored in a long double data type. Both

LDBL_MIN and LDBL_MAX are found in afloat.h header file.

  1. double Data Type

The double data type is used to store large real values. It takes eight bytes in memory. Its range is from 1.7 x 10-308 to 1.7 x 10+308. It provides the accuracy of 15 decimal places.

DBL_MIN represents the smallest value that can be stored in double data type.

DBL_MAX represents the largest value that can be stored in double data type. Both

DBL_MIN and DBL_MAX are found in afloat.h header file.

  1. float Data Type

The float data type is used to store real values. It takes four bytes in memory. Its range is from

x 10-38 to 3.4 x 10+38. It provides an accuracy of 6 decimal places.

FLT_MIN represents the smallest value that can be stored in the float data type.

FLT_MAX represents the largest value that can be stored in the float data type. Both FLT_MIN and FLT_MAX are found in afloat.h header file.

 

C++ Identifier

Advertisement