Preprocessor Directives 361
b) When the file name is included without double quotation marks, the search for file is made
only in the standard directories.
Example # include <stdio.h>
# include <udf.h>
11.9 Write a program to call the function defined in "udf.c" file.
# include <8tdio.h>
# include <conio.h>
# include *udf .c*
void main ()
{
clrscr () ;
displayO;
I
Q in y irL
Function called
Contents of udf.c file.
int display();display () {printf ("n Function Called''); return 0;(
Explanation In the first program the "u d f. c " is included. It is a user defined function file. It is
complied before the main program is compiled. The complete programs along with the included one
are executed. The output of theprogram "Punction Called" is displayed.
11.6 CONDITIONAL COMPILATION
The most frequently used conditional compilation directives are # i f , #e lse , #endi f etc. These
directives allow the programmer to include the portions of the codes based on the conditions. The
compiler compiles selected portion of the source codes based on the conditions. The syntax of the
# if def directives is given below.
Syntax
#if d e f c id e n tifie r>
{
statementl;
statement 2;
}
#else
{
statement3;
statement4;
}
#endif
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 );
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.176.99