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.

Syntax:

#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.

Syntax:

#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.

MACRO USES
_DATE_ To get current date.
_TIME_ To get current time.
_FILE_ To get current file.
_LINE_ To get current line number.
_STDC_ 1

 Predefined Macros:

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

Example:

#include<stdio.h>  
#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;  
}

Output

PI :3.140000
Date :Sep 19 2018
Time :11:43:00
Line :8
STDC :1