Unit_3
Unit_3
o #include
o #define
o #undef
o #ifdef
o #ifndef
o #if
o #else
o #elif
o #endif
o #error
o #pragma
The #include preprocessor directive is used to paste code of given file into
current file. It is used include system-defined and user-defined header files.
If included file is not found, compiler renders error.
1. #include <filename>
2. #include "filename"
The #include <filename> tells the compiler to look for the directory where
system header files are held. In UNIX, it is \usr\include directory.
The #include "filename" tells the compiler to look in the current directory
from where program is running.
1. #include<stdio.h>
2. int main(){
3. printf("Hello C");
4. return 0;
5. }
Output:
Hello C
#include notes:
Note 3: You can use only comment after filename otherwise it will give
error.
C Macros
1. Object-like Macros
2. Function-like Macros
Object-like Macros
1. #define PI 3.14
Function-like Macros
C Predefined Macros
File: simple.c
1. #include<stdio.h>
2. int main(){
3.
4. printf("Date :%s\n", __DATE__ );
5. printf("Time :%s\n", __TIME__ );
6.
7.
8. return 0;
9. }
C #pragma
Syntax:
1. #pragma token
1. #pragma argsused
2. #pragma exit
3. #pragma hdrfile
4. #pragma hdrstop
5. #pragma inline
6. #pragma option
7. #pragma saveregs
8. #pragma startup
9. #pragma warn
1. #include<stdio.h>
2. #include<conio.h>
3.
4. void func() ;
5.
6. #pragma startup func
7. #pragma exit func
8.
9. void main(){
10. printf("\nI am in main");
11. getch();
12. }
13.
14. void func(){
15. printf("\nI am in func");
16. getch();
17. }
Output:
I am in func
I am in main
I am in func