0

Diference between " a%2 and a%2 == 0 " anyone please explain.

Assignment or equivalent

11th Nov 2016, 9:30 AM
Minko Terziyski
Minko Terziyski - avatar
5 Respostas
+ 12
We can look at an example to be more clear. For example , you have a variable named "b" .. if you write b = a%2, b will be equal to the reminder after division by 2. On the other hand, if we write b = (a%2 == 0), b will be true, if the the reminder of "a" after division by 2 is 0 (b is even), and be will be false, if the reminder will NOT be 0 (number is odd). Is it clear? :)
11th Nov 2016, 10:11 AM
Rebeka Asryan
Rebeka Asryan - avatar
+ 2
In general in C++ the expression with just one equal " =" means an assignment, it means you declare a value or a fact, for example a=5, or a=b ..., it means that a equals 5 or a equals the b variable. The expression two equal signs "==" means that you compare value with other value, for example a==5 means: Is the value of variable ' a ' equals the value 5? and the answer always yes or no, true or false. So the = is used to make an assignment and the double == is used in the logic operations to compare values or variables and the answer either TRUE or FALSE.
11th Nov 2016, 1:51 PM
Rami Jerus
Rami Jerus - avatar
+ 2
b=a%2 means that you declare that b is equal the remainder of the division of a/2. while b==a℅2 means that you ask :I"s the reminder of a/2 equals b?"
11th Nov 2016, 1:56 PM
Rami Jerus
Rami Jerus - avatar
+ 1
a%2 will just return the reminder when a is divided by 2. a%2==0 will check whether the reminder calculated is equal to '0' or not. and if reminder=0, it will return 'TRUE' or '1'. else it will return 0.
11th Nov 2016, 10:20 AM
P Sandesh Baliga
P Sandesh Baliga - avatar
0
equal to zero
16th Nov 2016, 8:38 AM
AKSHAY SONAWANE
AKSHAY SONAWANE - avatar