types of data in c++


types of data
types of data


This is our 2nd tutorial about C++ Tutorials, in this article you are going to learn about variable or type of data in c++.

you can also  read our previous c++ tutorial

introduction to c++

so let start our today tutorials .

variable :        

Variaable are most important part of any language. A variable has a symbolic name and can be given a variety of values. Variable are located in particular places in computer’s memory . When a variable is given a value , that values is actually placed in memory spaces assigned to variable .

most popular languages use same general variable types , such as integers , floating point numbers, and characters . You must declare a variable before using it . However ,you can declare variable  any where in program. If is not essential to declare variable before first executable statements . However it’s perhaps more understandable if normally used variable are found at beginning of program.


Declaration and Definition:

A declaration familiarizes a variable name into a program and states its type such as float ,char or int. however , if a declaration also sets apart memory for variable , it is also called a definition

The statement


In the above  program are definition , as well as declaration , because they set aside memory for x and y.


Variable Names in c++ :  

Variable Names in c++ :
The program INTVARS uses variable named var1 and var2 . the names given to variable are called identifiers . What are rules for writing identifiers?

You can use upper and lower letters and numarical value from 1 to 9 . Yunderscore (_) can also used as variable name . The first letter  char must be a letter

Or underscore. Identifiers can be as long as you can like most compilers will only recognize  first few hundred char.

However you can not use a c++ keywords as a variables name. a keywords are predefined words with a special meaning .int , for , while , do, else etc are example of keyword in c programming .

Data type 


int type

Integer  types of data  :

Integer variable represent integer numbers like 5, 50,000  and -100 . Such numbers are use for counting discrete numbers of objects like 25 book or 30 pens. Unlike floating point numbers, integers have no fraction part , you can express idea of four using integers, but not four and one half.

 Defining integer variable in C++:

Integer variable exist in several sizes, but most commonly used is type int. the amount of memory occupied by integer types is system dependent .

On a 32bit system such as windows, an int occupies 4 bytes (which is 32bit) or 1byte equal to 8bit. This allows an int to hold numbers in range from

-2,17,483,648 to    2,17,483,648 . Here is a program that defines and uses several variables of type int.



two integer variable  var1 and var2 .  the keyword int signals type of variable. These statement , which called declaration , must dismiss with a semicolon(;)  like other program statements .  the equal sign (=) as you might guess, causes the value on right to be assigned to variable on let.  The = in c++ is to the :=

char data type
char data type

char data type:

char data type stores integers that range in value form -128 to 127. char data type occupy only 1 byte (8 bits) of memory . char data type are sometimes used to store numbers that confine themselves to this limited range, but they are much more commonly used to stor e ASCII characters.


float data type
float data type

float data type

Floating point variable characterize numbers with a decimal place like 5.0012,  0.001259 and -200.023. given values have both part decimal part and floating part..  float data type variables represent what mathematician call real numbers,which are used for measurable quantities such as  area , temperature and distance .  They typically have a fractional part.  There are three kinds of float data type in c++ , type float, type double and type long double .

Let revise all of them one by one.

float data type in c++

Type float stores numbers in range of about 3.4×10 power -38 to 3.4×10 power of 38, with a precision of seven digits   . it occupies 4bytes(32bits) in memory .

Here simple example of  float data type


double data type &   long double


The larger floating point types , double data type and and long double, are similar to float except that they require more memory space and provide a broader range of values and extra precision. double data type involves 8 bytes of storage and handles numbers in range

from 1.7×10 power -308 to 1.7×10 power of 308 with a precision of 15 digits.  long double is compiler dependent but  often same as double.

boolean type

Variable of Boolean type can have only two values  true and false . in theory a boolean type requires only one bit of storage, but in practice compilers often store them as btes because a bye van be quickly accessed, while an individual bit must be extracted from a byte,

which requires additional time.  Type bool is most commonly used to hold results of comparisons. Is alpha less than bets ?

If so, a bool value is given value true ; if not , it’s given value false.


Summary :

in this article you have learnt about types of data in c++

int data type

char data typ

float data type

double data type and long double data type.

if you have any question related to this tutorials , you are always welcome.

thanks for reading

please share it with your friends

please read next tutorial:

loop in programming

Leave a Comment