The #define directive is specially used to define a micro i.e. single identifier that are equivalent to expression , complete statement or group of statements.
It is a fragment of code which has been given a name . Whenever the name is used , it is replaced by the contents of the macro.
Syntax:-
#define macroname microexpansion
Example:-
#define PI 3.14
#define ADD(a,b) (a+b)
Predefined Macros in C Language
Predefined Value
Macro
__DATE__ String containing the
current date
__FILE__ String containing the file name
__LINE__ Integer representing the
current line number
__STDC__ If follows ANSI standard
C,then value is a
non zero integer
__TIME__ String containing the
current time
How to use predefined Macros?
Find the current time using C program
#include <stdio.h>
main()
{
printf("Current time : %s ", __TIME__);
}
Output:-
Current Time:- 12:32:43
Some Important C program using Macro:-
> C program to calculate the arae of circle using macro.
> C program to find the sum of two number using macro.
> C program to find square of a number using macro.
> C program to find maximum between two number using macro.
Some other important c program:-
Important C program of 1D Array
Important C program of Matrix(2D Array)
Important C program of string
Important C program using Function
Important C program using Recursive function
Click Here to download complete notes of C programming.
It is a fragment of code which has been given a name . Whenever the name is used , it is replaced by the contents of the macro.
Syntax:-
#define macroname microexpansion
Example:-
#define PI 3.14
#define ADD(a,b) (a+b)
Predefined Macros in C Language
Predefined Value
Macro
__DATE__ String containing the
current date
__FILE__ String containing the file name
__LINE__ Integer representing the
current line number
__STDC__ If follows ANSI standard
C,then value is a
non zero integer
__TIME__ String containing the
current time
How to use predefined Macros?
Find the current time using C program
#include <stdio.h>
main()
{
printf("Current time : %s ", __TIME__);
}
Output:-
Current Time:- 12:32:43
Some Important C program using Macro:-
> C program to calculate the arae of circle using macro.
> C program to find the sum of two number using macro.
> C program to find square of a number using macro.
> C program to find maximum between two number using macro.
Some other important c program:-
Important C program of 1D Array
Important C program of Matrix(2D Array)
Important C program of string
Important C program using Function
Important C program using Recursive function
Click Here to download complete notes of C programming.
Comments
Post a Comment