362 Programming and Data Structures
The #i f def preprocessor tests whether the identifier has defined substitute text or not. If the identifier
is defined then #i f block is compiled and executed. The-compiler ignores #else block even if errors
are intentionally made. Error messages will not be displayed. If identifier is not defined then #else
block is compiled and executed.
11.10 Write a program to use conditional compilation statement as to whether the identifier
is defined or not
# include <etdio.h>
# Include <conio.h>
4 define LIMB 1
void main ()
{
clrscr ();
MfdefUNlE
printf ("This is line number one.");
#else
printf ("This is line number two.");
tiendif
getcheO;
)
OUTPUT;
This is line number one.
Explanation In the above program # i f de £ checks whether the LINE identifier is defined or not. If
defined the # if block is executed. On execution the output of the program is " This is line number one “.
In case the identifier is undefined the #else block is executed and output is " This is line number two".
11.11 Write a program similar to above with conditional compilation directives as to whether
the identifier is defined or not.
# Include <atdio.h>
# include <canio.h>
# define E •
void main ()
{
int a,b,c,d;
clrscr ();
mfdefE
I
aE2;
bE3;
printf ("A = % d & B = % d ",a ,b );
}
%else
t
c -2;
d=3;
printf ("C = % d & D = % d ’V ,d );
}