difference between macro and function?

Answer Posted / subrat pattnaik

1.In Inline function if the codes are too much it acts as
normal function(without expanding in a line it gets jumps to
fun defination) but this is not with macro(it gets inserted
were it is calleed without checking its bulkness).
2.Suppose
#define square(x) (x*x)

inline void SQUARE(int x)
{
x*x;
}

void main()
{
a=5;
cout<<"The square is "<<square(++a);
cout<<"The SQUARE is "<<SQUARE(++a);
}
Here in macro it will b ++a * ++a(a incrementing 2 times)
In inline it will get incremented and is squared(++a)^2
Thanks

Is This Answer Correct ?    10 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Can notepad ++ run c++?

546


Can malloc be used in c++?

568


What is polymorphism and its type in c++?

594


Describe private, protected and public?

600


What are the advantages of prototyping?

565






What is virtual base class uses?

711


Show the declaration for a pointer to function returning long and taking an integer parameter.

576


How much do c++ programmers make?

564


Can you explicitly call a destructor on a local variable?

602


What is a pointer with example?

659


What is stack unwinding?

606


What are virtual functions in c++?

689


Why should you learn c++?

587


Difference between struct and class in terms of access modifier.

695


How many different levels of pointers are there?

656