Introduction to Variables
Explore the concept of variables in C++ by understanding how they store data with specific types and unique names. Learn why variables are essential for managing and modifying data during program execution.
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.
📝 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
Variables are named locations in computer memory where we can store our data.
True
False
Let’s move on to the next lesson where you will see the basic syntax for declaring and initializing variables in C++.