Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

Explain the differences between macros and subroutines.

Macros Vs Subroutines

(i) Macros are pre-processor directives which are processed before the source program is passed to the compiler.

Subroutines are blocks of codes along with a exact task, to be performed and are directly passed to the compiler.

(ii) In a macro call the pre-processor replaces the macro template along with its macro expansion, in a literal manner.

As against this, into a function call the control is passed to a function with exact arguments, some computations are performed in the function and a helpful value is returned back from the function.

(iii) Macro raises the program size. For illustration, if we use a macro hundred times in a program, the macro expansion goes in our source code at hundred various places. Because the function makes the program smaller and compact, for example, if a function is used, the even if this is called from hundred various places in the program, this would take similar amount of space in the program.

(iv) Macros compose the program run faster as they have already been expanded and placed into the source code before compilation. While, passing arguments to a function and obtaining back the returned values does take time and would thus slow down the program.

(v)   Illustration of macro

#define AREA(x) (3.14*x*x) // macro definition main(){

float r1=6.25, r2=2.5, a;

a=AREA(r1); // expanded to (3.14 * r1 * r1)

printf("\n Area of circle =%f",a);

a=AREA(r2); // // expanded to (3.14 * r2 * r2)

printf("\n Area of circle= %f",a);} Example of subroutine

main(){

float r1=6.25, r2=2.5, a;

a=AREA(r1); // calls AREA() printf("\n Area of circle =%f",a); a=AREA(r2); // calls AREA()

printf("\n Area of circle= %f",a);}

float AREA(float r) // subroutine{

return 3.14*r*r;}

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M9544430

Have any Question?


Related Questions in Computer Engineering

What are content management systems cms describe the

What are Content Management Systems (CMS). Describe the challenges in implementing and maintaining CMS. Can internet search engines be considered as Content Management Systems - explain your answer.

Reading the biographybook where the body meets memory by

Reading the Biography Book : "Where the Body Meets Memory" by David Mura Questions: On page 62 to 66, David Mura talked about an incident when he was in fifth grade. A bully called Mike Wrangel was trying to beat up anot ...

The system development team at the xyz company is working

The system development team at the XYZ Company is working on developing a new customer order entry system. In the process of designing the new system, the team has identified the following data entity attributes: Invento ...

The stock price for international business machines ibm

The stock price for International Business Machines (IBM) historically has followed an approximately normal distribution (when adjusting for inflation) with a mean of $155.483 and standard deviation of $4.0278. What is t ...

Suppose that you have 5000 and you are contemplating the

Suppose that you have $5000 and you are contemplating the purchase of two investments, IBM and Walgreen's. One year from now, IBM can be sold at $ X per dollar invested, and Walgreen's can be sold for $ Y per dollar inve ...

It has been argued that although there may be more claims

It has been argued that although there may be more claims when road conditions are slippery in the winter, this should not affect the average claim. Malpeque took a sample of 50 claims from the winter of 2018 and found t ...

You really need help with this assignment please provide

You really need help with this assignment. Please provide step by step instructions and screenshot of the steps and execution, so I can follow how to complete this assignment. Prof. Orlando Karam maintains an Ubuntu Linu ...

Question after reading this weeks materials please respond

Question : After reading this week's materials, please respond to TWO of the following questions. CITATION IN APA 1. Compare mean time between repair (MTTR) and mean time between failures (MTBF). Why can more components ...

Question suppose that nickels and pennies disappear from

Question : Suppose that nickels and pennies disappear from the currency system and we have only dimes and quarters. Obviously any product that costs 15 cents can not be exactly paid for using only dimes and quarters. Sho ...

Strings in cstrings manipulationwrite one main code with

Strings in C++ Strings manipulation Write one main code with the following functions. Toggle Write a function called toggle() that accepts a string, and an integer. The function checks whether the character at the positi ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As