What is use of macro arguments in c? what is major difference between normal macro definition and macro arguments.

Showing Answers 1 - 3 of 3 Answers

tkvenki

  • Jan 18th, 2006
 

Macro Arguments serve as inline functions.The major advantage is to add to the readability of code.A normal MACRO definition will not have any arguments.The fuction it performs it is independednt of any variables.But a MACRO with arguments.....will act according to the parameters passed.example: #define SQR 2*2 ------->Whereever u call SQR the answer is 4.... #define SQR(x) x*x --------> Here the answer depends upon the value of x.

  Was this answer useful?  Yes

mef526

  • Feb 13th, 2006
 

In above answer the macro SQR(4-y) doesn't work as expected. Can you see why?

A macro is not an inline function, it is a text replacement done by the C preprocessor. Think of it as a search and replace with replaceable parameters.

 

  Was this answer useful?  Yes

kapil mandge

  • Feb 25th, 2006
 

Macro is not inline function: we can see here...

#SQR(x) x*x

void inline SQR(int x){

x*=x;

}

if we call macro

SQR(++y) than it will work like this ++y*++y, value of y increamenting twice.

but when we call inline function value is increamented only once i think that is right.

  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