Explain the differences between macros and subroutines, Computer Engineering

Assignment Help:

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;}


Related Discussions:- Explain the differences between macros and subroutines

Show basic types of transmission technologies, Q. What are the basic types ...

Q. What are the basic types of Transmission technologies, basis on which computer networks will be categorized? Ans: Broadly there are two kinds of transmission technology:

Electric typewriter in information distribution, Electric typewriter : Ele...

Electric typewriter : Electric typewriters are similar to standard typewriters but with an electronic motor taking the place of human energy. It is much faster than the standard m

Senior project, any ideas about senior project topic

any ideas about senior project topic

Combining goals and design principles, The Set Book assignment should enabl...

The Set Book assignment should enable you to begin talking about the usability of interactive products in terms of a variety of parameters. Instead of simply saying 'nice cell phon

#logic function, Minimize the following logic function using K-maps and rea...

Minimize the following logic function using K-maps and realize using NAND and NOR gates. F(A,B,C,D) =?_m(1,3,5,8,9,11,15) + d(2,13).

Cryptarithmetic problem in artificial intelligence, Solve the following cry...

Solve the following cryptarithmetic problem using Prolog: P I N G P O N G + F U N --------- I G N I P Each of the 7 different letters stands for a different digit. The

Define interrupt and isr, Define interrupt and ISR? An interrupt is a r...

Define interrupt and ISR? An interrupt is a request from an I/O device for service by the processor. The processor gives the requested service by implementing the interrupt ser

What are the main features of uml, What are the main features of UML ...

What are the main features of UML Defined system structure for the object modelling Support for all different model organization Strong modelling for behaviour an

Explain about the value chain for a manufactured product, Explain about the...

Explain about the value chain for a manufactured product. The products sold in shops and purchased for use within organizations are the result of a complicated web of relations

What is the difference between intranet and extranet, What is the differenc...

What is the difference between intranet and extranet? Given table illustrates brief overview of the differences among the three kinds of the network: Network

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