C++ Variables

Variables are use to store values in mental memory. Suppose you want to use different values in your C++ program, firstly you have to store them. For this purpose variables are use.

For example: you want to store 5 in your mental memory then you want to store 15 at the same time. Then you use different variables to store your data.

  1. a = 5;
  2. b = 15;

Here a and b are variables. You can give a variable any name you want. In other words variable is the name of your stored data.

Variable Declaration

To use of variables in C++, you must assigns a data type to that variables. The syntax of declaring a variable is;

  • Int a;
  • Char b;
  • Float num;

Here int, char and float are the data types that tells us what type of data is stored in variables.

Variable initialization

After declaration, you need to initialize your variable. The syntax of initialization of variable is;

Int a=0;

Types and description

  1. Void: Represents the absence of type.
  2. Int: Integer type could be signed or unsigned depending on the range of data stored. Signed types shows both positive and negative values but unsigned types shows only positive values.
  3. Long int: long integer.
  4. Float: It is use when data is in decimal form.
  5. Double: It is same as float, but it could be use when data is too long.
  6. Long double: Long double precision floating point number.
  7. Char: It is use when you want to store characters. For example you want to store name, grade etc.
  8. Bool: It has been introduced to store Boolean value, true or false.