Pre-processor to Define String in C Programming



Pre-processor to Define String in C Programming

Program to define Printf Statement using #define

#include<stdio.h>
#define PRINT printf("%s",str)

void main()
{
char *str = "Pritesh";
PRINT;
}

Output :

Pritesh

Program to define String

#include<stdio.h>
#define STR "Pritesh Taral"

void main()
{
printf("%s",STR);
}

Output:

Pritesh Taral

Program to use format specifier inside MACRO

#include<stdio.h>
#include<conio.h>
#define FORMAT "%s",str

void main()
{
clrscr();
char *str="Pritesh";
printf(FORMAT);
}

Output :

Pritesh