Зміст курсу
Introduction to C++
Introduction to C++
Types of Variables
In the previous chapters, we printed some expressions. However, what to do if we need to store these expressions for future usage? In C++ (like in other programming languages) there are containers to keep data - variables. For each type of data (numbers, strings, characters) there is a type of variable.
Let’s take a look at the most often used types:
Why do we need to know the type of each variable? In Python, for example, you can store the data without worrying about its type.
When you declare variables in C++, the type of variable is a mandatory parameter, so knowing and correctly using data types will help to avoid many mistakes.
Let's look at an example of a variable declaration:
int num = 42; cout << num;
You can also reassign your variable if it’s needed:
double num = 3.2; num = 12.44; cout << num;
You might also declare a variable but assign the value later or define the multiple variables of the same type in one declaration:
Завдання
Practice:
- Declare the variable
x
type ofstring
. - Assign the value
"Hello"
to the variablex
( don’t forget about double quotes). - Reassign
x
to the"Bye"
. - Print the variable
x
after these operations.
Don’t forget about semicolon ;
at the end of lines.
Дякуємо за ваш відгук!
Types of Variables
In the previous chapters, we printed some expressions. However, what to do if we need to store these expressions for future usage? In C++ (like in other programming languages) there are containers to keep data - variables. For each type of data (numbers, strings, characters) there is a type of variable.
Let’s take a look at the most often used types:
Why do we need to know the type of each variable? In Python, for example, you can store the data without worrying about its type.
When you declare variables in C++, the type of variable is a mandatory parameter, so knowing and correctly using data types will help to avoid many mistakes.
Let's look at an example of a variable declaration:
int num = 42; cout << num;
You can also reassign your variable if it’s needed:
double num = 3.2; num = 12.44; cout << num;
You might also declare a variable but assign the value later or define the multiple variables of the same type in one declaration:
Завдання
Practice:
- Declare the variable
x
type ofstring
. - Assign the value
"Hello"
to the variablex
( don’t forget about double quotes). - Reassign
x
to the"Bye"
. - Print the variable
x
after these operations.
Don’t forget about semicolon ;
at the end of lines.
Дякуємо за ваш відгук!
Types of Variables
In the previous chapters, we printed some expressions. However, what to do if we need to store these expressions for future usage? In C++ (like in other programming languages) there are containers to keep data - variables. For each type of data (numbers, strings, characters) there is a type of variable.
Let’s take a look at the most often used types:
Why do we need to know the type of each variable? In Python, for example, you can store the data without worrying about its type.
When you declare variables in C++, the type of variable is a mandatory parameter, so knowing and correctly using data types will help to avoid many mistakes.
Let's look at an example of a variable declaration:
int num = 42; cout << num;
You can also reassign your variable if it’s needed:
double num = 3.2; num = 12.44; cout << num;
You might also declare a variable but assign the value later or define the multiple variables of the same type in one declaration:
Завдання
Practice:
- Declare the variable
x
type ofstring
. - Assign the value
"Hello"
to the variablex
( don’t forget about double quotes). - Reassign
x
to the"Bye"
. - Print the variable
x
after these operations.
Don’t forget about semicolon ;
at the end of lines.
Дякуємо за ваш відгук!
In the previous chapters, we printed some expressions. However, what to do if we need to store these expressions for future usage? In C++ (like in other programming languages) there are containers to keep data - variables. For each type of data (numbers, strings, characters) there is a type of variable.
Let’s take a look at the most often used types:
Why do we need to know the type of each variable? In Python, for example, you can store the data without worrying about its type.
When you declare variables in C++, the type of variable is a mandatory parameter, so knowing and correctly using data types will help to avoid many mistakes.
Let's look at an example of a variable declaration:
int num = 42; cout << num;
You can also reassign your variable if it’s needed:
double num = 3.2; num = 12.44; cout << num;
You might also declare a variable but assign the value later or define the multiple variables of the same type in one declaration:
Завдання
Practice:
- Declare the variable
x
type ofstring
. - Assign the value
"Hello"
to the variablex
( don’t forget about double quotes). - Reassign
x
to the"Bye"
. - Print the variable
x
after these operations.
Don’t forget about semicolon ;
at the end of lines.