Storage Classes File Handling
Preprocessor :- Preprocessor means that process before the actual compilation. Preprocessor always start with # except define() . It increases the readability of the program.
Ex:- #define , #if , #else , #include , #undef , #endif etc
#include :-it is used to import any file or to call any file in the current program.
#include<stdio.h>
it searches the file in the include folder of the c if it presents it simply calls all methods or members of the file or if the file doesnot exists then it will give compile time error.
#define:- it is used for substituting the value.
Ex:
#include <stdio.h>
#define a 10
main()
{
int b;
b=a;
printf("%d",b);
}
output:-10
Description:- compiler will replace the value of a with 10 and transfer it to b.so it prints 10.
Macros with Arguments:- we also write macros with arguments
Ex:-
#include<stdio.h>
#define a 10
#define sum(b) (a+b)
main()
{
int b =2;
int sum=0;
sum = sum(b);
printf("%d",sum);
}
Output:- 12
Description:- in this first it replace the value of a with 10 and when we call the sum(b)
it passes the value of i.e 2 as a argument . and in #define it adds a and b and the sum is transfer into the sum .
so it prints 12
Predefined Macros in C:-
Ex;-
#include<stdio.h>
main()
{
printf("%s",_FILE_);
printf("%s",_DATE_);
printf("%s",_TIME_);
printf("%d",_LINE_);
printf("%d",_STDC);
}
Output:-first it display the file name.
display the current date
display the time
it contains the current line number
it gives 1 when it follows ANSI STANDARD.
Preprocessor :- Preprocessor means that process before the actual compilation. Preprocessor always start with # except define() . It increases the readability of the program.
Ex:- #define , #if , #else , #include , #undef , #endif etc
#include :-it is used to import any file or to call any file in the current program.
#include<stdio.h>
it searches the file in the include folder of the c if it presents it simply calls all methods or members of the file or if the file doesnot exists then it will give compile time error.
#define:- it is used for substituting the value.
Ex:
#include <stdio.h>
#define a 10
main()
{
int b;
b=a;
printf("%d",b);
}
output:-10
Description:- compiler will replace the value of a with 10 and transfer it to b.so it prints 10.
Macros with Arguments:- we also write macros with arguments
Ex:-
#include<stdio.h>
#define a 10
#define sum(b) (a+b)
main()
{
int b =2;
int sum=0;
sum = sum(b);
printf("%d",sum);
}
Output:- 12
Description:- in this first it replace the value of a with 10 and when we call the sum(b)
it passes the value of i.e 2 as a argument . and in #define it adds a and b and the sum is transfer into the sum .
so it prints 12
Predefined Macros in C:-
Ex;-
#include<stdio.h>
main()
{
printf("%s",_FILE_);
printf("%s",_DATE_);
printf("%s",_TIME_);
printf("%d",_LINE_);
printf("%d",_STDC);
}
Output:-first it display the file name.
display the current date
display the time
it contains the current line number
it gives 1 when it follows ANSI STANDARD.
No comments :
Post a Comment