Created
February 2, 2015 09:28
-
-
Save amastov/71802029bb4881e9a909 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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