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

Explain brief about class and objects, Question 1 Write a program that acc...

Question 1 Write a program that accepts a 3x3 matrix from the user and finds the transpose of it Question 2 Explain Brief about class and objects. Also describe friend functi

C program to convert number to binary, Write a program in C that you will n...

Write a program in C that you will name "divide.exe", to divide one 32-bit twos-complement binary number by another, giving the quotient and the remainder, using the subtract-shift

Matlab assignmnet, I have a Matlab assignment and I have the assignment des...

I have a Matlab assignment and I have the assignment description+ algorithm + and the output sample. the files are on a dropbox folder and you can download them from the link below

Overloading unary operators using friend function, O v e r l o a d i ...

O v e r l o a d i n g U n a r y Op e r a t o r s Us i n g F r i e n d F u n c t i o n cl a ss s i g n { i n t a ,

Write a program that allows two players to play connect four, You may work ...

You may work in pairs for this assignment. Submit only one project per team; both partners will receive the same grade. Also, you can earn up to 40 points (out of 25) on this assig

Ans, A palindrome is a string that reads the same from both the ends. Given...

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

Program is to append the contents of one file to another, Program is to app...

Program is to append the contents of one file to another: void main()    {   clrscr();   fstream file1,file2;   char st1[13],st2[13];/* 13 because a filename canno

Need a solution, Hello. I need a solution for this assignment. It is for C+...

Hello. I need a solution for this assignment. It is for C++ Language: Create a BusinessPartner class that contains a first name, company name, and a telephone number. Create a Con

Explain the working of strcpy function, Explain the Working of strcpy Funct...

Explain the Working of strcpy Function? strcpy() : This function is meant to use to copy one string to another. The strcpy function as well accepts two strings as arguments.

String function examples, 1. De ne a function chomp :: String -> String tha...

1. De ne a function chomp :: String -> String that selects a run of repeated characters from the start of a string with the run being as long as possible. For example ch

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