course content

Course Content

Introduction to C++

VariablesVariables

With the help of variables, we can "borrow" the memory of our PC and use it to store any data to operate on it later. Creating a variable consists of two parts – 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 of the piece of memory that we "borrowed".

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

Note

Number 0 also takes up memory :)

cpp

main.cpp

In the case of declaring several variables that contain data of the same kind, it is convenient to indicate the type of information only once (all numbers are integer):

cpp

main.cpp

or

cpp

main.cpp

1. What is variable?
2. Why are variables used?

question-icon

What is variable?

Select the correct answer

question-icon

Why are variables used?

Select the correct answer

Section 2.

Chapter 1