Introduction to Variables

Get introduced to variables.

We'll cover the following

Variables #

Suppose we have cabinets of different types. In each cabinet, we can only put one item. To store something in a cabinet, first, we’ll decide the cabinet type. Then, we’ll put a unique label on a cabinet to keep track of the item it contains.

A variable is just like a cabinet that can store data. To store something in a variable, we decide its data type (similar to a cabinet type) and give it a unique name (analogous to a label in the above diagram). Each variable can store exactly one item, but the data stored in a variable can be changed over time.


In terms of programming language, a variable is a location in the computer's memory where we can store data. The value of this data can be changed during the execution of a program. Each variable has a unique and meaningful name which is known as an identifier.


📝 Note: A big advantage of variables is that they allow us to store data so that we can use it later in the program. We can always change the value of a variable during the running program.

Quiz

Q

Variables are named locations in computer memory where we can store our data.

A)

True

B)

False


Let’s move on to the next lesson where you will see the basic syntax for declaring and initializing variables in C++.