C Macro function

What is Macro?

Simplified function is called macro.
Whenever a function body contains one or two statements then it is called simplified function.
In implementation whenever the simplified function is occurred then in place of creating the function recommended to go for macro.

Macro Advantages:

Macros are faster than normal function.
No physical memory will be allocated for macros.
When we are working with the macros, substitution will take place in place of bouncing process.

Macro Drawbacks:
In macros, compilation errors will not be checked.
In macros, type checking process will be not occur.
No control flow statement can be placed in a macro.
Return statement cannot be placed in macro.

Example:

int sum(int x,int y)
{
return(x+y);
}

void main()
{
int s;
s=sum(10,20);
printf(“sum=%d”,s);
}

Powered by k2schools