Programming

Variables In C++

proteachc++

Variables

In

C++

Variables are a BOX of a certain data type which contains a value related to its respected data type.

 

The main 6 types of Data Types of Variables in C++ are:

  • int

  • char

  • double

  • float

  • string

  • bool

 

All the variables that we declare contain a certain name that while coding we can give.

All the variables that we declare contain an initial value which we give them at the time of declaration. (If we do not store some value it will contain a garbage value automatically given by the system)

 

  • int

 

int is a data type of a variable which means integer.

Only an integer value can be stored in it. For example:

22, -100 i.e. any integer value.

 

  • int number = 89;

This means an int type variable is created which has a name number and its value is 89.

 

  • Size of int is 4 bytes.
  • The size of int variable varies from system to system.

 

  • double

 

double is a data type of a variable which means DECIMAL NUMBERS (double integer). It can store integer or DECIMAL NUMBERS (double integer) value in it. For example:

2, 22.1, 2.5, -9.56 i.e. any integer or DECIMAL NUMBERS (double integer) value.

 

  • double can contain up to 15 decimal digits.

 

  • Size of double is 8 bytes.

 

  • double number = 1.5;

This means a double type variable is created which has a name number and its value is 1.5.

 

  • double number = 1;

This means a double type variable is created which has a name number and its value is 1.0 it will be printed as 1.0

 

 

  • char

 

char is a data type of a variable which means character.

All the character value can be stored in it. For example:

‘c’ , ‘q’, ‘1’ , ‘+’ i.e. any character value.

 

  • These values while declaration or whenever written in code are surrounded with single quotes.

 

  • Size of char is 1 bytes.

 

  • char number = ‘a’;

This means a char type variable is created which has a name number and its value is a.

 

  • float

float is a data type of a variable which means floating integers. There is small difference between float and double variable. It can store integer or DECIMAL NUMBERS (floating integer) value in it. For example:

2, 22.1, -2.5, -9.56 i.e. any integer or DECIMAL NUMBERS (floating integer) value.

 

  • Float can contain up to 7 decimal digits only and double can contain up to 15 decimal digits.

 

  • Size of float is 4 bytes.

 

  • float number = 1.65;

This means a float type variable is created which has a name number and its value is 1.65.

  • float number = 2;

This means a double type variable is created which has a name number and its value is 2.0 it will be printed as 2.0

 

  • string

string is a data type of a variable which means a string of characters. We can be store a string (text) in it. For example:

“PRO-TEACH” i.e. any string.

  • STRING is always written in double quotes.

 

  • string number = “PRO-TEACH”;

This means a string type variable is created which has a name number and “PRO-TEACH” is stored in it.

 

  • bool

 

bool is a data type of a variable which means boolean.

Only a TRUE and FALSE value can be stored in it. For example:

true ,false or 1, 0 i.e. any integer value. No other value can be stored in it.

  • Size of bool is 1 bytes.

 

  • bool number = true;

This means a bool type variable is created which has a name number and its value is 1.

  • bool number = false;

This means a bool type variable is created which has a name number and its value is 0

 

 

 

 

 

6 Comments

6 Comments

  1. rehan

    December 24, 2019 at 8:03 am

    nice work…!! really helping

  2. Rimsha

    December 28, 2019 at 8:09 pm

    It is really helpful!! Please upload more lectures related programming

  3. qasim

    January 14, 2020 at 7:43 am

    it is so helpful

  4. Walter Wueste

    March 7, 2020 at 1:05 am

    Hi, the Variables In C++ – Pro Teach Articles article it
    is well written, it’s very informative.
    Give Your Child the Most Important Skill in Life – Reading.

    I found the Most Effective Method to Teach my Children to Read:
    http://bit.ly/Teach-Your-Child-to-Read
    Your child deserves the best education! 🙂 Kiss you All!

  5. cbd for sex

    May 6, 2020 at 10:56 am

    cbd oil companies

  6. best cbd oil

    May 20, 2020 at 6:27 pm

    Appreciation to my father who shared with me concerning this website, this blog is actually remarkable.|

Leave a Reply

Your email address will not be published.

Most Popular

To Top