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.

    

Related Posts:

  • Enumerated Data Type Enumerated Data Type     This is one of the user defined datatypes. The use of this datatype is to make programs more readable.It allows you to create your own datatype with predefined values. Though its form … Read More
  • Inroduction To PreProcessors Inroduction To PreProcessors INTRODUCTION:     The C preprocessor is a program that processes our source program before it is passed to the compiler.This is a  capability that does not exist in many other … Read More
  • Pointers And Structures Pointers And Structures  We know that the name of an array stands for the address of its zeroth element.The same thing is true of the names of  arrays of structure variables.Suppose product is an array variabl… Read More
  • Unions Unions  As array represent group of data items that belong to the same type. C supports  a  constructed data type known as structure and unino, which are methods for packing data of different types. … Read More
  • Introduction To Storage Classes Introduction To Storage Classes strong class provides information about their location and visibility.The storage class decides the portion of the program within which the variables are recognized. A variables storage cl… Read More

0 comments:

Post a Comment