Defining a macro to output the value of an expression
#include <stdio.h>
#define print_value(expr) printf("\n" #expr " = %lf", (double)expr);
void main() {
int n = 10;
double f = 6.5;
print_value( n );
print_value( f );
printf("\n");
print_value(f * f + 4.0);
print_value( n / 2 + 3);
print_value( 3 * 4 + 12 / 2 - 8);
printf("\n");
}
Related examples in the same category