What are the advantages of Macro over function?
Answers were Sorted based on User's Feedback
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 |
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 |
What is scanf_s in c?
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 ...
What is a sequential access file?
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); }
What is a structure in c language. how to initialise a structure in c?
What are the phases in s/w developed life cycle? wat is the diff b/w stack & queue...where do we use stack
What is a scope resolution operator in c?
To what value are pointers initialized? 1) NULL 2) Newly allocated memory 3) No action is taken by the compiler to initialize pointers.
What does the file stdio.h contain?
What do you mean by c?
Can variables be declared anywhere in c?
What math functions are available for integers? For floating point?