Define constant using #define - C Preprocessor

C examples for Preprocessor:Preprocessor Operators

Description

Define constant using #define

Demo Code

#include <stdio.h>
#define TWO 2        //from   w  w  w . j  a va2  s  . c o  m
#define OW "line 1\
line 2" /* a backslash continues a definition to the next line*/


#define FOUR  TWO*TWO
#define PX printf("X is %d.\n", x)
#define FMT  "X is %d.\n"

int main(void){
    int x = TWO;
    
    PX;
    x = FOUR;
    printf(FMT, x);
    printf("%s\n", OW);
    printf("TWO: OW\n");
    
    return 0;
}

Result


Related Tutorials