Why is a macro used in place of a function?
a) To save memory
b) To increase speed
c) For inline expansion
d) All of the above
Answer:
d) All of the above
Explanation:
Macros in C are often used in place of functions to increase speed and save memory because they provide inline expansion of code. When a macro is invoked, its code is directly inserted into the program at the point of invocation, avoiding the overhead of a function call. This can lead to faster execution and more efficient use of memory, especially in small, frequently-used pieces of code.
However, macros should be used with caution, as they can make the code harder to debug and maintain.