C++ Variables

A variable is nothing but a name given to a storage area that our programs can manipulate. This location is used to hold the value of the variable, which determines the size and layout of the variable’s memory.

Following are the rules for Naming C++ Variables:

  • Variable name must begin with a letter or underscore.
  • They are case sensitive.
  • They can be constructed with digits, letters.
  • No special symbols are allowed other than underscore.

Declaring and Initializing a variable:

Declaration

Declaration of variables must be done before they are used in the program.

Declaration does the following things.

  • It tells the compiler what the variable name is.
  • It specifies what type of data the variable will hold.

Initializing

Initializing a variable means to provide it with a value. A variable can be initialized and defined in a single statement, like:

Let’s write a program in which we will use some variables.

OUTPUT