Let us go back to expressions and operators, which we already discussed in the previous episodes. An expression appears, for example, in an assignment, such as here. In this case, the expression is necessarily at the right side of the "equal to" sign. Since it calculates a value, this value has to be of the same type as the variable on the left side of the "equal to" sign. Indeed, the value computed by the expression will be assigned to the variable. An expression can be as simple as a literal value, such as 4 or 3.14 . By the way, please note that C++ uses the anglo-saxon syntax. However, an expression can also be a formula, such as here, where we multiply the variable n by itself; we thus get n squared, logically. Multiplication is represented by the asterisk symbol ( * ). Expressions can also include other mathematical symbols such as addition, subtraction. We can also use parentheses; this is therefore rather general. One must be aware, when writing expressions, that literal values all have their own type, exactly as variables do. For example, if I write 1, simply, this 1 is an int-type literal value. However, if I write 1.0, this 1.0 will be of type double. Please note that we can simply write " 1. " instead of " 1.0 " and this 1. will still be of type double. Therefore, we can write a declaration like this, simply with 1. and this is strictly equivalent to this declaration here. Obviously, though writing " 1.0 " will always be more readable than the short " 1. "; therefore, please favor the " 1.0 " notation. We can also use the scientific notation, namely, we can write " 2e3 " for 2 times 10 to the third, that is, 2000. So 2e3 is 2000. In general, " aeb " is a times 10 to the b. For example, in this declaration, we initialize the variable to 1.3 multiplied by 10 cubed, that is 1300. In this declaration, we initialize our variable y to 1.3 times 10 to the -3 , that is, 0.0013. Moving on to the operators, we have the usual operators, such as the addition, written with the + (plus) symbol, the subtraction, written with the - (minus) symbol, the multiplication, written, as we said, with the * (asterisk) character and the division written with the / (slash) character. However, there is trick regarding the division : if both values involved in a division are of type int, then it is the integer division. For example, in this division, 1 and 2 are two literal values, both of type int. Therefore, it is the integer division and the result will be 0. Why ? Because 1 is equal to 0 times 2 and the remainder is 1, therefore, the result of the integer division is this 0. Another example thereof is 5 divided by 2; we will obtain 2 because 5 is 2 times 2 and the remainder is 1. Therefore the result of the division is this 2. However, if one of the two values appearing in the division is of the type double, the other value will automatically be converted to the type double, namely, this 1 will be converted to a double, which we can write 1.0 We will get the division 1.0 divided by 2.0 and obtain, as expected, 0.5 In C++, we can also use the operators : + = (plus equal), - = (minus equal ), * = (multiplied equal ) and / = (divided equal ). For example, we may write a += 5 which is strictly equivalent to writing a = a + 5 Another example : we may write a *= b which is strictly equivalent to a = a * b In the case of int and ONLY in the case of int, we can also use an operator called modulo and written with the % (percent) sign returning the remainder of the integer division. For example, 11 % 4 (11 modulo 4) is 3. Because ? 11 is equal to 2 times 4 and the remainded is 3. And the remainder is precisely the result of the modulo. Another example : 12 modulo 4... is, in your opinion ? 0 Why so ? Because 12 is equal to 3 times 4 and the remainder is 0. And this 0 is the result of the modulo. There are other operators written ++ (plus plus) et -- (moins moins) and are called increment and decrement operators; they permit to add 1 to variables or subtract 1 from variables. For example, we may write ++i which is strictly equivalent to i = i + 1 which will add 1 to the variable i. We may also write --a which is equivalent to a = a - 1 which will subtract 1 from the value of the variable a. These operators are very useful, especially in "for loops" which will be discussed in the next lesson. Until now, we have only seen decimal values and double-type variables on one side and integer values and int-type variables on the other. But what happens when, for example, we try to assign a decimal value to an int-type variable ? For example, we have here a double-type variable x, containing the value 1.5 We declare here an int-type variable n, which we represented here. Now, through this assignment, we try to assign the value 3 times x, that is, 4.5 to our int-type variable n, which is designed to store integers. What will happen in such a case ? The compiler will convert the literal value 4.5 , which is of type double to an int-type value. This conversion will be done automatically, losing the fractional part. Therefore, 4.5 will be converted to 4. This 4 is now of type int and we will be able to assign this 4 to the int-type variable n. Please note that the conversion from the double type to the int type is a very particular case. We also have the conversion from int to double. However, these are two exceptions. In genere, C++ is what we call a strongly typed language, which will require that, for example in an assignment, the part on the right of the equal to be of the same type as what is on the left of the equal. Let us go back to the trap of the integer division. We have declared here a double-type variable x, which we represented here. In this assignment, we assign the value of the expression 1/2 to our variable x. In your opinion, what will x contain after this assignment ? Since 1 and 2 are two int-type literal values, this division is the integer divion. 1/2 is 0 in the case of the integer division. Thus, we will assign the value 0 to the variable x. The fact that x has been declared as a double-type variable does not change anything here. In an assignment, we always evaluate what is on the right side of the equal sign, no matter what is on the left side of the equal sign. A problem can arise, when, for example we try to calculate the average of integer values. For example, here, we have declared two variables : note1 initialized to 4 and note2 initialized to 5. (TN: note means grade) They are both of type int. Now, we want to calculate their average; we would like to obtain 4.5 However, if we proceed to this declaration, in this expression note1 and note2 are both of type int, therefore, note1 + note2 is also of type int; this literal value 2 is also of type int. This is thus the integer division. We will therefore obtain 9 divided by 2, that is 4, while we wished to obtain 4.5 A possible solution is to proceed as follows : Here, we still have note1 and note2 of type int, still initialized to 4 and 5. We initialize "moyenne" to the result "note1 + note2" (TN: moyenne means average). note1 + note2 is 9, of type int but we assign it to "moyenne", which has been declared as a double-type variable. Therefore, "moyenne" will contain 9, which we could write 9.0 in order to show that it is double-type value. This time, when we write " moyenne /= 2 " which is strictly equivalent to "moyenne = moyenne / 2 " , since, this time, moyenne is of the type double, this 2, albeit of type int, will be converted into a double-type value, which we could write 2.0 We will thus calculate 9.0 divided by 2.0 this is the classical division and the result will be indeed be 4.5 We will assign this 4.5 to the variable "moyenne". We can also use mathematical functions in expression. To that end, we simply need to add the line : " #include cmath " at the beginning of the program. If, for example, we wish to calculate the sine of an angle, we will ba able to use the function "sin", such as here. By the way, the trigonometric functions in C++, expect angles in radians. So, if we have an angle of 10 degrees, such as here, we will convert it into radians thanks to this expression, and send its value to the function "sin" so that it will return the sine of this 10 degrees angle. It is really that easy. You have here a rather complete list of mathematical functions available in C++ . The most interesting functions are probably the trigonometric functions sin, cos and tan expecting, remember, angles in radians, the exponential function, written "exp", the natural logarithm, written "ln" in mathematics, is written "log" in C++ . The function power, x to the y is written "pow(x, y) in C++ . The square root is written "sqrt". The absolute value is written "abs" We can also use several mathematical constants; even though they are not officially defined by the C++ standard, most compilers will recognize them. For example, we have Pi, which is written M_PI (M underscore PI) in capital letters and e, which is the base of the natural logarithm which is written M_E (M underscore E) also in capital letters. For example, if we have an angle, expressed in degrees, which we want to convert into radians, we will use this formula here. Namel multiply the degree angle by Pi and divide by 180. In C++, it will be written as follows : We obtain Pi's value by writing M_PI, we multiply by the angle and divide by 180. By the way, since this expression is of type double, we have no problem with the integer division, here.