Quote:
|
Originally Posted by newdigital
I want to ask about arithmetical operators.
1. It is written the following:
A = B + C, with description that add A to B and assign the result to C.
Is it mistake?
The same with A = B - C.
|
It’s a mistake. It would be:
A = B + C; "
Add B to C and assign the result to A."
A = B - C; "
Subtract C from B and assign the result to A."
I have updated the lesson , please donwload it
Quote:
|
Originally Posted by newdigital
2. And I do not understand A = A % C, with description: A is remider of division of B on C(ex: 10%2 will produce 0).
May you explain? :confused:
|
The remainder operator works by dividing the first number by the second number for the first integer results and then
returns the remaining number.
For example:
10%5=0
This is because if you divide 10 by 5 you will get 2 and there no remaining value, so the remainder is 0.
10%8=2
This is because if you divide 10 by 8 you will get 1 (1*8=8), so the remainder is (10-8 = 2).
100%15=10
This is because if you divide 100 by 15 you will get 6 (6*15=90), so the remainder is (100-90=10).
What about 6%8?
It will be 6 because if you divide 6 by 8 you will get 0 (8*0=0), so the remainder is (6-0=6).
Quote:
|
Originally Posted by newdigital
3. It was mentioned that we can not write as:
A=(B++)*5
we must write: :confused:
A++;
B=A*5
May be the following:
B++;
A=B*5
|
The rule is "You can’t combine the increment and decrement operator with other expressions.".
So you can't write:
A=(B++)*5;
or
B=(A++)*5;
But you can write:
A++;
B=A*5;
And
B++;
A=B*5;
How is it work?
Let’s take a live example:
int A=1; //set A to 1
int B;
A++; //increase A by 1, now A=2
B=A*5 //which means B=2*5