VariablesVariables

By using variables, we can effectively utilize our computer's memory to store data for future operations. The process of creating a variable involves two essential steps: declaration and initialization. Variable names in C++ can consist of letters and numbers but cannot start with numbers, nor can they contain spaces or arithmetic operators (such as +, -, etc.).

To declare a variable, you need to specify the stored data. In our case, it is an integer value with the name myVariable.

Under the hood of the name is the address to the piece of memory that we are using for this variable.

Now, to initialize the variable, it is necessary to drop something into that section of memory, in our case, it is an integer (int).

Note

Number 0 also takes up memory :)

cpp

main.cpp

When declaring multiple variables that hold the same type of data, it is convenient to specify the data type only once.

cpp

main.cpp

question-icon

Why are variables used?

Select the correct answer

Everything was clear?

Section 2. Chapter 1