Skip to content

Instantly share code, notes, and snippets.

@Noxwizard
Created July 10, 2020 05:52
Show Gist options
  • Save Noxwizard/8b1b2c51ab35ee8c8558af733b516fce to your computer and use it in GitHub Desktop.
Save Noxwizard/8b1b2c51ab35ee8c8558af733b516fce to your computer and use it in GitHub Desktop.
Parentheses matter...
#include <stdio.h>
#define VAL0 123
#define VAL1 1*123
#define VAL2 (1*123)
int main()
{
int mod0 = 2 % VAL0;
printf("mod0: %d\n", mod0);
int mod1 = 2 % VAL1;
printf("mod1: %d\n", mod1);
int mod2 = 2 % VAL2;
printf("mod2: %d\n", mod2);
int mod3 = 2 % 123;
printf("mod3: %d\n", mod3);
return 0;
}
$ ./modtest
mod0: 2
mod1: 0
mod2: 2
mod3: 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment