using == with an assignment expression

What is this saying exactly?

int result = (num1 % num2) == 0

I don't understand how the == 0 works. If the statement doesn't make sense here is where I got it from an example from Ivan Hortons book. The example finds prime numbers, but that is not important, I just don't how or what the == 0 does.

Here is a snippet of the example code:

for(int i = 0; i < count; i++)
{
found = (trial % *(primes + i)) == 0; //true for exact division
if(found)
break;
}

if(found ==0)
*(primes + count++) = trial; //found a prime assign it to prime array.

If I take out the == 0 from: found = (trial % *(primes + i)) == 0;
found is always 1 or true. I don't understand how this works.
1
2
3
4
5
6
7
int remainder = (trial % *(primes + i));
if(remainder == 0){
	found = true;
}
else{
	found = false;
}


It's just a more elegant and shorter way of writing the above.
Last edited on
Thank you very much!
Topic archived. No new replies allowed.