Wednesday, 28 August 2013

Issue with % operator in C

Issue with % operator in C

I am having an issue with the % operator in C. I know that the % operator
gives the remainder of a division. However when faced with a question like
1 % 2 or 3 % 2, I get confused. After googling this, I found different
solutions.
Some say that as 1 / 2 is 0.5, we round it down to 0. So 1 % 2 is 0.
Others say that as 1 / 2 is 0.5, we instead round it up, like we would in
maths, to 1. So 1 % 2 is 1.
And therefore, I am now confused. My question is: What is 1 % 2?
Thank you in advance :):)

No comments:

Post a Comment