Uses string concatenation and the # operator - C Preprocessor

C examples for Preprocessor:Macro

Description

Uses string concatenation and the # operator

Demo Code

#include <stdio.h>
#include <math.h>
#define PR(X, ...) printf("Message " #X ": " __VA_ARGS__)

int main(void)
{
    double x = 48;
    double y;//from   w  ww  . j  a va 2s.c om
    
    y = sqrt(x);
    PR(1, "x = %g\n", x);
    PR(2, "x = %.2f, y = %.4f\n", x, y);
    
    return 0;
}

Result


Related Tutorials