I want to calculate: (-15 % 3) which should be 0 but instead i'm getting 1:
When i explicitly do:
int IntFcn (const void *key, size_t tableSize)
{
printf("%d\n",(*(int*)key)); // prints -15
printf("%d\n",tableSize); // prints 3
printf("%d\n",(-15) % 3); // prints 0
}
I get the right result (0) but when i try to use the variables below i get 1:
int IntFcn (const void *key, size_t tableSize)
{
printf("%d\n",(*(int*)key)); // prints -15
printf("%d\n",tableSize); // prints 3
printf("%d\n",((*(int*)key) % tableSize)); // prints 1
return ((*(int*)key) % tableSize);
}
Why is this happening?