Data Types in C++

Data Types in C++

Data types in C++ is the type of data that a variable can be hold. for example, an integer can hold integer data, a character can hold character data, etc.It is specifies the size and type of information the variable.

Example of data type in C++

int age = 10y  ;

Data types are divided into three groups:

    • Built-in
    • User-defined
    • Derived

Built in data types

 

Data Type Size Description
int 4 bytes int is stores the whole numbers, without decimals
float 4 bytes float is stores the fractional numbers, containing one or more decimals.
double 8 bytes double is also stores fractional numbers, containing one or more decimals and this data type is sufficient for storing 15 decimal digits
boolean 1 byte boolean is stores true or false values
char 1 byte char is stores a single character, or ASCII values

1. Integer

keyword int is used for integer data type. The size of integer is 4 bytes and ranging from -2147483648 to 2147483647.

Example of integer data type

int number = 567;

2. Character

Keyword char is used for character data type. It requires 1 byte of memory space. Its range is from -128 to 127 or 0 to 255.

When declare a character variable, enclose the character within single quotes (‘ ’).

Example of character data type

char name = 'StudyExperts';

3. Floating Point

Keyword float to represent floating point (decimal and exponential) values. It is also known as single-precision floating point data type. It requires 4 bytes of memory space

Example of floating point

float area = 23.55;

4. Double Floating Point

Keyword float and double reprent  floating point number. Double floating point has twice the precision of float and it require 8 bytes of memory space. So, it is also called double-precision floating point data type.

Example of double floating point

double volume = 127.4935;
double value = 25E11;

5. Boolean

Keyword boolis used to store boolean values, that means they can either be true or false. Size of bool is 1 byte.

Syntax of boolean

bool cond = false;

Data type Modifiers

Data type Size (in Bytes) Description Example
signed int / int 4  signed int stores integers signed int n = -40;
unsigned int 4 unsigned int is stores 0 and positive integers unsigned int n = 40;
short / signed short 2 short and signed short is equivalent to short int or signed short int, it stores small integers ranging from -32768 to 32767 short n = -2;
unsigned short 2 unsigned short isequivalent to unsigned short int and it stores 0 and small positive integers ranging from 0 to 65535 unsigned short n = 2;
long 4 long is equivalent to long int, stores large integers long n = 4356;
unsigned long 4 unsigned long is equivalent to unsigned long int and it stores 0 and large positive integers unsigned long n = 562;
long long 8 long long is equivalent to long long int and it stores very large integers long long n = -243568;
unsigned long long 8 unsigned long long equivalent to unsigned long long int and it stores 0 and very large positive integers unsigned long long n = 12459;
long double 12 long doubleS is stores large floating-point values long double n = 432.6781;
signed char / char 1 signed char and char is stores characters ranging from -128 to 127 signed char ch = ‘b’;
unsigned char 1 unsigned char is tores characters ranging from 0 to 255 unsigned char ch = ‘g’;

 

Derived Data Types

Derived data types is the Data types that are derived from fundamental data types. There are of four types of derived data types these are, Function, Array, Pointer and Reference.

 

 

Read more,

C++ programming language

Share this post

Leave a Reply

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