Q5. How Are Macros Different From Inline Functions?
•Macros are normally used whenever a set of instructions/tasks have to be repeatedly performed. They are small programs to carryout some predefined actions. •We normally use the #define directive in case we need to define the values of some constants so in case a change is needed only the value can be changed and is reflected throughout. #define mul(a,b) (a*b) •The major disadvantage of macros is that they are not really functions and the usual error checking and stepping through of the code does not occur. •Inline functions are expanded whenever it is invoked rather than the control going to the place where the function is defined and avoids all the activities such as saving the return address when a jump is performed. Saves time in case of short codes. inline float add(float a,float b) { return a+b; } •Inline is just a request to the compiler and it is upto to the compiler whether to substitute the code at the place of invocation or perform a jump based on its performance algorithms.