Preprocessor Directives 371
printf ( “ Small Case");
}
else
{
f=isdigit(d);
if(f!=0)
printf (" n %c is a digit",d);
else
{
f=ispunct(d);
if(f!=0)
printf (" n % c is a punctuation sym bol",d);
}
}
)
getcheO;
OUTPUT:
Enter any character: C
C is a letter in Capital case
Explanation In the above program a character is entered through the keyboard. The macro i salpha
() checks whether it is a digit or a letter. It returns true or false value to variable d. The i f condition
checks the value of variable d. If the entered character is a letter the i f block is executed and again the
macro i supper () checks whether the character is capital or small. Thus appropriate messages are
displayed.
If theentered character isnot aletter else block of firstif statement is executed. The macro is d igit
() checks whether the character is digit or any other symbol. If it is digit i f block is executed otherwise
else block is executed. In the else block macro ispunc t () checks whether the entered character is
punctuation symbol. If so the message is displayed.
SU MM AR Y
In this chapter you have studied one of the most useful feature of the C language i.e. the preprocessor
directive. It supports the programmer to write portable programs, which can be executed, on different
types of systems. After having gone through this chapter and on execution of programs, you also have
the knowledge and uses of #def ine # #undef, # include, #lin e, token pasting and stringizing operator,
conditional compilation through illustrated examples. You too, have learnt how to display programmer's
own error messages using te rro r d irectiv e and making various warnings on/off displayed by
compiler using #pragma directive. You are also aware of the pre-defined macros and their uses.
EXE RC ISES
A) Answ er the following questions to the p o in t
1) What is a preprocessor directive?
2) What is the # inc lude directive? H ow does it help the programmer?