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

Pointer to function, how many values we can return from pointer to function...

how many values we can return from pointer to function?

What does throw; (with no exception object after the throw , What does thro...

What does throw; (with no exception object after the throw keyword) mean? Where would I employ it? A: You should see code that looks something like this: class MyException

Determine the capacitor voltage by c program, Write a program to determine ...

Write a program to determine V c for a given value of time (t)   #include stdio.h #include math.h void main() {      char prompt;   float vs,cr,t,vc;   /* input time */

Change to palindrome, A palindrome is a string that reads the same from bot...

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement. Your task is to convert S to palindrome

Padovan string, padovan string for natural numbers program in java /...

padovan string for natural numbers program in java // aakash , suraj , prem sasi kumar kamaraj college program 1 : package test.padovanstring; public class Padov

#include, Write a program to find the area under the curve y = f(x) between...

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points can b

Virtual ATM, #questio A charitable organization wants to design a special A...

#questio A charitable organization wants to design a special ATM machine to be used by needy people. The association supplies the needy person with a pin number to be able to use

Algorithm, algorithm to prepare mark sheet of a student by inputing name,br...

algorithm to prepare mark sheet of a student by inputing name,branchcode,semester,register no,5 marks of students and total mark of student

Define an asset base class, a) Define an Asset base class that provides the...

a) Define an Asset base class that provides the following method: class Asset { public:      virtual double getValue()=0; };   This will be the base class for both stock an

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