Variables Type in C++

A variable furnishes us with named capacity that our projects can control. Every variable in C++ has a particular type, which decides the size and format of the variable's memory; the scope of values that can be put away inside that memory; and the arrangement of activities that can be applied to the variable.

The name of a variable can be made out of letters, digits, and the underscore character. It must start with either a letter or an underscore. Upper and lowercase letters are particular in light of the fact that C++ is case-touchy −

There are various sorts of types in c++.

Sr.NoType Description
1boolStores either value true or false.
2charTypically a single octet (one byte). This is an integer type.
3intThe most natural size of integer for the machine.
4floatA single-precision floating point value.
5doubleA double-precision floating point value.
6voidRepresents the absence of type.
7wchar_tA wide character type.

Declaring (Creating) Variables

To make a variable, you should indicate the type and assign out it a value:

Syntax: -

type variable = value;

Where type is one of C++ types, (for example, int), and variable is the name of the variable, (for example, x or myName). The equivalent sign is utilized to relegate(assign) values to the variable.

Example: -

Make a variable called myNum of type int and assign it the value 15:

int myNum = 15;
cout << myNum;

Example: -

You can also declare a variable without assigning the value, and assign the value later:

int Num;
Num = 15;
cout << Num; //Num is 15

in the event that you assign a new value to a current variable, it will overwrite the past value.

Example: -
int Num = 15; //Num is 15
Num = 10; //Num is 10
cout << Num; //Output of Num is 10

Display Variables: - The cout object is used together with the << operator to display variables.

To combine both text and a variable, separate them with the << operator:

Example: -

int Age = 18;
cout << "I am " << Age << " years old." ;