Module: (C++) Arithmetic expressions


Problem

1/7

C++ Assignment operator

Theory Click to read/hide

C++ Assignment operator

We already know that you can set the value of a variable using the input staememt.
The input statement is used in cases where the value is set by the user during program execution.

But very often we need to set a new value for a variable, calculating it according to a certain formula. In this case, the assignment operator will help us

The general form of the assignment operator is as follows:
<variable> = <expression>;

The assignment operator works as follows:
1. First, the expression to the right of the assignment sign is calculated.
2. The received value of the expression is saved (they say "assigned") in the variable standing to the left of the assignment sign. In this case, the old value of the variable is erased.

For example, if we need to set the variable c to the double value of the variable b, then we will have to write it like this:
с = 2 * b;

Remember that in programming you cannot omit the multiplication signs in an expression. Otherwise, the computer does not understand what you want to multiply.
For example, you can’t just write c = 2b, it will be wrong!

Problem

In the seventh line write the assignment statement, as a result of which the variable c takes the value of the sum of the variables a and b.