J
jason
Hi,
I learned my lesson about passing pointers, but now I have a question
about macros.
Why does the function work and the MACRO which is doing the same thing
on the surface, does not work in the following small example ?
#include <stdio.h>
#define PERCENTAGE(a, b) (((a - b) / a) * 100.0)
double percent(double a, double b) {
return ((a - b) / a) * 100.0;
}
int main(void) {
printf("%g%%\n", percent(1000, 100));
printf("%g%%\n", PERCENTAGE(1000, 100));
return 0;
}
Thank you !
jason
I learned my lesson about passing pointers, but now I have a question
about macros.
Why does the function work and the MACRO which is doing the same thing
on the surface, does not work in the following small example ?
#include <stdio.h>
#define PERCENTAGE(a, b) (((a - b) / a) * 100.0)
double percent(double a, double b) {
return ((a - b) / a) * 100.0;
}
int main(void) {
printf("%g%%\n", percent(1000, 100));
printf("%g%%\n", PERCENTAGE(1000, 100));
return 0;
}
Thank you !
jason