What is the difference between a macro and a function in C?

MacroFunction
Text replace by the preprocessorCompiled code that is called
No type checkingTypes are checked
Code is copied at each use (bigger program)One copy of the code
Faster, no call overheadSmall call overhead
Arguments can run two times (SQUARE(i++))Arguments are evaluated once

Use a function when you can. Use macros for constants and small tricks only. See Preprocessor and Macros.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.