C Macros

C Macros:

A macro value in C replaces a part of a program with a value already defined by #define directive.

Macros can be of four types:

Object-like Macros:

When a macro is simply replaced by a value, then it is called as Object like Macro.


#define macro_Name macro_Value

Function-like Macros:

When a macro is replaced by a logic, same as in a function, then it is called as Function like Macro.


#define macro_Name macro_Logic

User Defined Macros:

Macros defined in a C program by the user, which are not defined in the C library are called as user defined Macros.

_DATE_To get current date.
_TIME_To get current time.
_FILE_To get current file.
_LINE_To get current line number.

 Predefined Macros:

Some macros are already defined in the C library, these macros are called as Predefined Macros.


#define PI 3.14  
void main()
printf("PI :%f\n",PI );    
printf("Date :%s\n", __DATE__ );    
printf("Time :%s\n", __TIME__ );    
printf("Line :%d\n", __LINE__ );    
printf("STDC :%d\n", __STDC__ ); 	 
return 0;  


PI :3.140000
Date :Sep 19 2018
Time :11:43:00
Line :8
Content Protection by DMCA.com
Please Share