What is variable in computer programming?



Variables are the names we give to computer memory locations which are used to store values in a computer program.

For example, assume we want to store two values 10 and 20 in our program and at a later stage, we want to use these two values. Let's see how we will do it.

Here are the following three simple steps:
  1. Create variables.
  2. Store values in those variables.
  3. Retrieve and use the stored values from the variables.

1. Creating variables
Creating variables is also called declaring variables in programming. Different programming languages have different ways of creating variables inside a program.

Example : 

var x;
var y;

2. Store values

Example : 

var x = 10;
var y = 20;

3. Retrieve and use

Example : 

var x = 10;
var y = 20;

System.out.println(x+y);


Comments