Defining a macro to output the value of an expression : Macro Function « Macro Preprocessor « C / ANSI-C






Defining a macro to output the value of an expression

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

1.Defining a macro to compare two valuesDefining a macro to compare two values
2.Generate a square tableGenerate a square table
3.Define small function in macro
4.Make string
5.Use marco for small function
6.Use macro to find the minor variable
7.Define Macro as simple function
8.Use Macro to check the int range
9.Use Macro to get the bigger int value