Which one would you prefer - a macro or a function, C/C++ Programming

Assignment Help:

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.

 


Related Discussions:- Which one would you prefer - a macro or a function

If one won''t explicitly call the destructor of a local then , if one won't...

if one won't explicitly call the destructor of a local; then how does he handle the above situation?

Recursion, write a cprogram to calculate fraction through recursion

write a cprogram to calculate fraction through recursion

Boardcoloring, how to fill the blank space in4*4 matrix?

how to fill the blank space in4*4 matrix?

C++ ASSIGNMENT, How much does it cost to complete a C++ assignment that is ...

How much does it cost to complete a C++ assignment that is 80% finished??

Implement a binomial tree class, a) Implement a binomial tree class with a ...

a) Implement a binomial tree class with a method that calculates the value of an option passed in to the class. The binomial tree should not rely on specific features of the differ

Flow chart, flow chart for calculating the volume of sphere

flow chart for calculating the volume of sphere

Explain the new and delete operators, The new and delete operators The ...

The new and delete operators The C language has explained library functions- malloc() and free() for dynamic allocation and de-allocation of memory. C++ gives yet another appro

Array, how to do an array

how to do an array

Tree, Write algorithm and program for the conversion of a Tree to a Binary ...

Write algorithm and program for the conversion of a Tree to a Binary Tree

System programing, #quesdifferentiate betweenrelocatable and self relocatin...

#quesdifferentiate betweenrelocatable and self relocating program with exampletion..

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd