Ask a Question


Start Coding Today




Data Structures


Interview Experiences

C Programming

C++ Programming

Java Programming



When are macros in c source code executed?

asked Mar 27 by anonymous

4 Answers

0 votes

Macros are not executed.

When you start compiling your code it gets replaced with macro definition.


#define data = 2*2

int main()
int j = data;
printf("%d", j);

In this case once the compilation starts, your code will look like

int main()
int j = 2*2;
printf("%d", j);

However you cannot see this as this is a part of compilation process.

answered Mar 28 by nihal
0 votes

Macros will not be executed, it will be replaced at pre-processing stage.

answered May 1 by vavajodu
0 votes

macro is a fragment of code which has been given a name. Whenever the name is used in the program, it is replaced by the contents of the macro.
For example :

#include <stdio.h> 
#define PI 3.1415 
int main() 
    float radius, area;
    printf("Enter the radius: ");
    scanf("%d", &radius);  
    area = PI*radius*radius;
    return 0; 

Here, wherever the macro PI is used, it will be replaced by 3.1415 at the pre-processing stage.

answered May 8 by Ranju Kumari
0 votes

Macros are not executed.

When you define a macro, then at the time of compilation of the code the variable which you have defined using macro gets replaced by the assigned value and the code gets executed.

Hence macros are quite fast than functions.

Almost like inline functions in case of Object Oriented Programming

answered May 9 by Prateek Chanda

Please log in or register to answer this question.