Variables

What, Why, and How of variables

Vatsal Kumar
3 min readSep 30, 2021

Variables are used to store information to be referenced and manipulated in a computer program. They also provide a way of labeling data with a descriptive name, so our programs can be understood more clearly by the reader and ourselves. Their sole purpose is to label and store data in memory.

What are variables?

A variable is a value in programming that can change depending on conditions or information provided to the program. Constants and variables are usually defined as specific data types. Each data type specifies and limits the data’s format.

Why should we use variables?

Variables are used in computer programs to store data that may be referenced and updated. They also enable us to give data a descriptive name, making our programs more understandable to both the reader and ourselves. They just exist to classify and store information in memory.

What are some examples of how variables can be used?

All but the simplest computer programs require variables to run. When software runs, it needs to store data in memory. This could be a number, a response to a query, or anything else. Variables are used as containers in most (if not all) software programming languages to keep numbers, phrases, or other essential information that is needed in multiple locations throughout your code. In a few common languages, here’s how they function. Variables are names used in software programming to hold one or more values or something else. Variables allow us to save, alter, and access data while the program is running.

In C, you define a variable by writing its TYPE followed by its name and then assigning it a value. In Java, you declare a variable by writing its TYPE followed by its name and then assigning it a value. (For instance, ‘int Jims age = 21;’). Declare a variable in ActionScript by writing “var” followed by the variable’s name, a colon, and finally the type.

Start using variables like this:

  1. Declare the variable and give it a name and a type.
  2. Give the variable a name and a value.
  3. Make use of the variable.

Examples of variables

‘a’ and ‘b’ are both variables. They are numerical symbols that can be used to represent any number. For example, the number 5 may be in variable ‘a,’ and the number 10 could be in variable ‘b.’ The expression “a + b” is changed with the Actual Values “5 + 10” during program execution, and the result is 15.

Conclusion:

Here we come to know the uses, examples, how to implement, What is variable, Why should we use a variable, and how to use a variable?

--

--

Vatsal Kumar
Vatsal Kumar

Written by Vatsal Kumar

Vatsal is a coding enthusiast and a youtuber

No responses yet