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
C Preprocessor and Macros
C File Handling
C Read From a File
C Command Line Arguments
Exercises & Assignments
No Content Found.
Interview Questions & Answers
What is the difference between const and #define in C?
What is the difference between #include with angle brackets and with double quotes in C?
What is the difference between a macro and a function in C?