What are the advantages of Macro over function?

Answers were Sorted based on User's Feedback



What are the advantages of Macro over function?..

Answer / hrpynux@gmail.com

When writing macros for functions, they saves a lot of time that is spent by the compiler for invoking / calling the functions. Hence, The advantage of a macro over an actual function, is speed. No time is taken up in passing control to a new function, because control never leaves the home function.

Is This Answer Correct ?    2 Yes 0 No

What are the advantages of Macro over function?..

Answer / Vipin Gautam

In C, macros have certain advantages over functions:
1. Compile-time Evaluation: Macros are replaced by the preprocessor at compile time, which can lead to better performance for repeated expressions.
2. Reduced Overhead: There is no function call overhead associated with macro usage as they don't require stack management or memory allocation/deallocation.
3. Inline Expansion: Macros are expanded inline, leading to potentially faster code execution since there's no function call or return involved.
4. Flexibility: Macros can perform bitwise operations, handle predefined constants, and even change the order of operations (due to lack of operator precedence).

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

What is scanf_s in c?

1 Answers  


write a c code "if you give a any decimal number then print that number in english alphabet"? ex: i/p: 552 o/p: five hundred fifty two ...

1 Answers   Philips,


What is a sequential access file?

1 Answers  


Give the output for the following program. #define STYLE1 char main() { typedef char STYLE2; STYLE1 x; STYLE2 y; clrscr(); x=255; y=255; printf("%d %d\n",x,y); }

2 Answers   ADITI,


What is a structure in c language. how to initialise a structure in c?

1 Answers  


What are the phases in s/w developed life cycle? wat is the diff b/w stack & queue...where do we use stack

6 Answers  


What is a scope resolution operator in c?

1 Answers  


To what value are pointers initialized? 1) NULL 2) Newly allocated memory 3) No action is taken by the compiler to initialize pointers.

4 Answers   Aricent,


What does the file stdio.h contain?

1 Answers  


What do you mean by c?

1 Answers  


Can variables be declared anywhere in c?

1 Answers  


What math functions are available for integers? For floating point?

1 Answers  


Categories