1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #include <stdio.h>
#include <stdlib.h>
#define log_int(x) printf("%s == %d\n", (#x), (x))
int triple(int n) {
return n * 3;
}
int main(int argc, char* argv[]) {
// GOOD
log_int(triple(5));
log_int(triple(4));
log_int(triple(3));
log_int(triple(2));
log_int(triple(1));
// Advantages over raw printf(…)
// ∙ Easy to "turn off" when it's time to submit your code.
// ∙ Less duplication means fewer oppportunities for bugs.
// BAD (… or less good)
printf("triple(5) == %d\n", triple(5));
printf("triple(4) == %d\n", triple(4));
printf("triple(3) == %d\n", triple(3));
printf("triple(2) == %d\n", triple(2));
printf("triple(1) == %d\n", triple(1));
return EXIT_SUCCESS;
}
/* vim: set tabstop=4 shiftwidth=4 fileencoding=utf-8 noexpandtab: */
|
© Copyright 2020 Alexander J. Quinn This content is protected and may not be shared, uploaded, or distributed.