0% found this document useful (0 votes)
14 views2 pages

Functions Intrview

The document discusses two types of macros in C: object-like macros and function-like macros. Object-like macros replace an identifier with a value, while function-like macros look like function calls. The document also mentions some common C predefined macros like __FILE__, __DATE__, and __LINE__.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Functions Intrview

The document discusses two types of macros in C: object-like macros and function-like macros. Object-like macros replace an identifier with a value, while function-like macros look like function calls. The document also mentions some common C predefined macros like __FILE__, __DATE__, and __LINE__.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Macros in C

A macro is a segment of code which is replaced by the value of macro. Macro is defined by
#define directive. There are two types of macros:

1. Object-like Macros
2. Function-like Macros

Object-like Macros
The object-like macro is an identifier that is replaced by value. It is widely used to represent
numeric constants.

For example: #define  PI  3.14  


Here, PI is the macro name which will be replaced by the value 3.14.

Function-like Macros
The function-like macro looks like function call.

For example: #define MIN(a,b) ((a)<(b)?(a):(b))  

Here, MIN is the macro name.

C Predefined Macros
ANSI C defines many predefined macros that can be used in c program.
C predefined macros example
File: simple.c

1. #include<stdio.h>  
2.  int main(){    
3.    printf("File :%s\n", __FILE__ );    
4.    printf("Date :%s\n", __DATE__ );    
5.    printf("Time :%s\n", __TIME__ );    
6.    printf("Line :%d\n", __LINE__ );    
7.    printf("STDC :%d\n", __STDC__ );      
8.    return 0;  
9.  }    

Output:

File :simple.c
Date :Dec 6 2019
Time :12:28:46
Line :6
STDC :1

You might also like