which one would you prefer - a macro or a


Which one would you prefer - a macro or a function?

Actually it depends on the purpose of program!

- In case of macros, corresponding code is inserted directly into your source code at the point where macro is called. No overhead is involved in using a macro. This makes Macros more efficient and faster than functions. Though, macros are generally small and can't handle large, complex coding constructs. So, if it's a complex situation that program wants to handle, functions are more suitable.

- Macros are expanded inline - this means that each time a macro occurs, code is replicated. So, code size in case of usage of macros would be larger in comparison to functions.

So, choice of using functions or macros actually depends of your requirement - speed vs. program size.

If your program includes small, repeated code sections, you must use Macros. If program requires, large number of unique code lines - you must prefer functions.

 

Request for Solution File

Ask an Expert for Answer!!
C/C++ Programming: which one would you prefer - a macro or a
Reference No:- TGS0355028

Expected delivery within 24 Hours