Sunday, 21 January 2018

Difference Between The Macros And Functions


Difference Between The Macros And Functions



Difference Between The Macros And Functions
Macros are like functions but there is difference between those two .

1. In macro call the processor replaces the macro template with its macro expansion. Where as in function call the control is passed to a function along with certain arguments, some functions are performed in the function and a useful value is returned back from the function.

2. Macros make the program run faster but increases the program size, where as functions make the program smaller and compact. i.e if the macro is used hundred times in the program , the macro expansion goes into source code for hundred times which increases the program size. otherwise if
the  function is used hundred times in the program from different places it takes same amount of space.



3. In the functions  while passing the arguments to a function  and getting back the returned value does take time and slow down the program. where as in macros this problem wont occurs since they have already been expanded and placed in the source code before compilation.

  At the conclusion it is came to know that if the macro is simple it makes a nice shorthand and avoids the overheads  associated with function calls. On the other hand if the program consists of large macro it can be replaced by the  function.

    

0 comments:

Post a Comment