Modulus understand even more.

Hello, i know how to use modulus but i dont understand what a part of this code means:

a % 2 == 0

what does 2 == 0 means? why is there a zero over there? and why is there a == there?

Thanks!
It checks if the remainder returned by a%2 is equal to 0. In particular this identifies even numbers.
Dont exactly understand, can you give me an example? thanks!
The modulus operator returns the remainder of the division. So for example if a = 8; 8 / 2 = 4 with no remainder. So 8 % 2 = 0. So your condition:

1
2
if ( a % 2 == 0 )
     cout << a << " is an even number. " << endl;
'==' checks if the things on either side of it are equal. If they are it returns true, else it returns false.
Thanks, finally got it.
Topic archived. No new replies allowed.