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

write a programme to get a character and thier ASCII value

2674


What type of question are asked in GE code writing test based on c++ data structures and pointers?

3597


Give 10 points of differences between C & C++.

737


How can you prevent accessing of the private parts of my class by other programmers (violating encapsulation)?

738


What is the purpose of ios::basefield in the following statement?

889






Define macro.

695


Write a function to find the nth item from the end of a linked list in a single pass.

655


How many types of scopes are there in c++?

663


Do you know the problem with overriding functions?

663


What is difference between n and endl in c++?

664


Explain deep copy?

695


What is dev c++ used for?

689


write a corrected statement in c++ so that the statement will work properly. x = y = z + 3a;

1531


Explain one method to process an entire string as one unit?

1089


What is binary search in c++?

684