Skip to content

Instantly share code, notes, and snippets.

@amastov
Created February 2, 2015 09:28
Show Gist options
  • Save amastov/71802029bb4881e9a909 to your computer and use it in GitHub Desktop.
Save amastov/71802029bb4881e9a909 to your computer and use it in GitHub Desktop.
/* Side effect, Macro versus Function */
#include <stdio.h>
#pragma warning(disable : 4996)
#define mac(a,b) a*a + b*b - 2*a*b
int func(int a, int b) {
return (a*a + b*b - 2 * a*b);
}
int main() {
int f, g, i, j, x, y;
printf("Please enter two integers\n");
scanf("%d%d", &f, &g);
printf("f = %d\tg = %d\n", f, g);
i = f;
j = g;
x = func(i, j);
y = mac(i, j);
printf("x = %d\ty = %d\n", x, y);
x = func(++i, ++j);
i = f;
j = g;
y = mac(++i, ++j);
printf("i = %d\tj = %d\n", i, j);
printf("x = %d\ty = %d\n", x, y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment