“C” Pre-Processor
Directives:
Pre-processors are executed first before
executing other program statements by the compiler, like Header Files.
Pre-processor statements are started with #
symbol (Hash Sign). These are also called “C” Pre-processor directives. There
are four types:
-
File
Inclusion (Header Files)
-
Macro
Expansion (Making
Constants)
-
Conditional
Compilation
-
Miscellaneous
File Inclusion: We have used
multiple functions in our program. If these functions are Pre-Defined or
Library Functions then we have to include some header files according to used
functions in our programs. These header files are always included top of the
program before all the functions and statements. We will use the keyword “include” to add a header file in the program.
Syntax: # include<header-file>
Ex: # include<stdio.h>
# include<math.h>
Macro Expansion: In macro expansion,
we will make a value as constant during
execution of the program. We will use the keyword “define”.
Use upper case letters only for assigning
constant name. Always placed after header files at top of the program. You have
to note that don’t use data-type, equal sign as assignment operator and semicolon as statement terminator.
Syntax: # define CONSTATNT-NAME value
Ex: # define PIE 3.14
# define DAYS 365
~~~~~~@~~~~~~
// Find
Area & Circumference of the Circle using Macro Expansion. ME_CIR.C
#
include<stdio.h>
#
include<conio.h>
#
define PIE 3.14
void
main( )
{
int r ;
float ar, cf;
clrscr( );
printf(“Input Radius of the Circle = “);
scanf(“%d”, &r);
ar=(float) PIE
* r * r;
cf=(float) 2 *
PIE * r;
printf(“\n Area = %f”, ar);
printf(“\n Circumference = %f”, cf);
}
~~~~~~@~~~~~~
No comments:
Post a Comment