Course Content
Introduction to C++
Introduction to C++
Variables
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 :)
main.cpp
When declaring multiple variables that hold the same type of data, it is convenient to specify the data type only once.
main.cpp
Why are variables used?
Select the correct answer
Everything was clear?