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

What is computer communications networks, Q. What is Computer communication...

Q. What is Computer communications networks? Computer communications networks are the outcome of a combination of computers and telecommunication products. An interconnected gr

Create a scatterplot for each set of variables, For each of the following v...

For each of the following variables: YEARofBIRTH transformed into a new variable called . To do this you will need to use the Command. Hint codes 9998 and 9999 are missin

Explain about microsoft access, Microsoft access name has been transformed ...

Microsoft access name has been transformed to Microsoft office access. This software incorporates relational database management system which joins GUI (graphical user interface) w

Error handling in hard disk, Error handling in Hard disk in computer archit...

Error handling in Hard disk in computer architecture : Modern drives also make widespread use of Error Correcting Codes (ECCs), specifically Reed-Solomon error correction.

What are the address-sequencing capabilities, What are the address-sequenci...

What are the address-sequencing capabilities required in a control memory? i. Incrementing the control address register ii. Unconditional branch as specified by address fiel

Give difference between assembler and interpreter, Give difference between ...

Give difference between assembler and interpreter. Assembler: It is the translator for an assembly language of computer. An assembly language is a low-level programming langu

Ida* search - artificial intelligence, IDA* Search - artificial intelligenc...

IDA* Search - artificial intelligence: A* search is a sophisticated and successful search strategy. In fact, a problem with A* search is that it must keep all states in its me

Wireless Networking, Suppose you work in a network security company, and yo...

Suppose you work in a network security company, and you need to prepare a survey report of a particular security issue of wireless networking. To start with, select an area of wire

Conversion of decimal number 82.67 to its binary equivalent, Conversion of ...

Conversion of Decimal number 82.67 to its Binary Equivalent Ans. Firstly see the integer part 82 and determine its binary equivalent  as The Binary equivalent is (101001

Parallel random access machines, PRAM is one among the models which are use...

PRAM is one among the models which are used for designing the parallel algorithm as shown in Figure. The PRAM model comprises the following components: i)  A group of identical

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