What is the similarities between macro and function?

Questions by skr_ymca   answers by skr_ymca

Showing Answers 1 - 8 of 8 Answers

sandeepyadav

  • Mar 3rd, 2006
 

macro are the special function but they consume very less time with respect ot function but there is some restriction in macro you do not use recursion as u can do in function.

  Was this answer useful?  Yes

priya

  • Mar 4th, 2006
 

HERE IN MACRO WE CAN DEFINE ANOTHER MACRO LIKE THAT OF FUNCTIONS

  Was this answer useful?  Yes

Ranjith

  • Mar 9th, 2006
 

Macro works similar to a function, but it's execution time is faster than function. Also, macro simply substitutes the value without performing calculatons where as function does calculations. The following example describes the difference between macro and function:

Macro:

#define sq(x) x*x

if you call sq(5+5), the result will be 35 becos macro directly substitutes the value. i.e, in this case, 5+5*5+5 = 35.

Function:

int sq(x)

{

       return x*x;

}

if you call sq(5+5) now, the result will be 100, because function calculates the argument value (if it has some calculations) and passes to the operation stack. i.e, in this case sq(5+5) will become sq(10) before passing to return x*x.

 

Hope this clears. Please let me know, if anybody know more about this

  Was this answer useful?  Yes

sandeep kuamr rao

  • Mar 10th, 2006
 

hello friend,

thanks for ur sweet efforts.

but i m sorry to say that i also knows what r the differences between macro and function............

 

actually i want to know what r the SIMILARITIES between macro and function?

i u know plz plz let me know also.

have a nice day..

bye.

 

 

  Was this answer useful?  Yes

vijay

  • Mar 10th, 2006
 

now, how do you declare a macro in vb.net

functions are declared as

public function functionname() as datatype

end function

what about a macro

  Was this answer useful?  Yes

aptuz

  • Jun 12th, 2006
 

As Priya says from her straight shoot line, that makes sense.

A MACRO CAN CALL ANOTHER MACRO WITH IN ITS DEFINITION, PRETTY MUCH LIKE IN FUNCTIONS.

#define sq(x) x * x; // finds square of 'x'
#define cu(x) sq(x) * x; // finds cube of 'x'

Here a macro calls another macro, which is strticly possible. The similarity in functions could look like this.

int sq(int x) { return ( x * x ); }
int cu(int x) { return ( sq ( x ) * x ); }

would be a valid equivalent set of statements that could do the same functionality as that of above macros.

Hope tha HELPS!!!

  Was this answer useful?  Yes

Megha

  • Nov 10th, 2006
 

Helo Ranjith....Thanx for explaining the difference b/w a macro and a function.......

  Was this answer useful?  Yes

VCCoder

  • Aug 6th, 2008
 

We can pass arguments into the macro as well as function.
We can say that a Macro is smilar to a global function

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions