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

What is static class data?

569


What do you mean by const correctness?

620


What are the effects after calling the delete this operator ?

549


Why do we need pointers?

577


What is the extraction operator and what does it do?

605






Incase of a function declaration, what is extern means?

513


What is lazy initialization in c++?

648


What is #include iostream?

728


Is it possible to use a new for the reallocation of pointers ?

589


What is binary search in c++?

559


Difference between overloaded functions and overridden functions

571


What is the difference between reference and pointer?

610


What is the best c++ compiler for windows 10?

576


Can you declare an array without a size in c++?

567


What is lvalue?

691