Can someone please explain the under-the-hood mechanics of x % y !=0 in C++? It evaluates to 0 if there is no remainder in integer division and it evaluates to 1 if there is any remainder of any amount. I find this to be quite useful, but I'd like to understand what is taking place, as the syntax is not intuitive to me.
I discovered this in a separate thread, which I do not have permissions to comment in:
Fast ceiling of an integer division in C / C++
Thank you.
(Please forgive any formatting faux pas; this is my first go here)
%is the integer remainder operator. For example:21 % 7 == 022 % 7 == 125 % 7 == 427 % 7 == 628 % 7 == 0x % y != 0is true if the integer division yields a non-zero remainder, false if it doesn't.x % yis simply that remainder;x % y != 0tests whether that remainder is non-zero.(Note that
x % y != 0can also be written as(x % y) != 0.)It's slightly complicated when you consider negative operands.