What is the difference between a macro and a function in C language?
A. A macro is a preprocessor directive that replaces a name with a code snippet and a function is a subprogram that performs a specific task
B. A macro is executed at compile time and a function is executed at run time
C. A macro does not perform type checking and a function performs type checking
D. All of the above
Answer:D
What is the difference between a macro and a function in C language?
A. A macro is a preprocessor directive that replaces a name with a code snippet and a function is a subprogram that performs a specific task B. A macro is executed at compile time and a function is executed at run time C. A macro does not perform type checking and a function performs type checking D. All of the above
Explanation: In the C language, there are two ways to define reusable code: macros and functions. A macro is a preprocessor directive that, prior to compilation, replaces a name with a piece of code. For instance, the macro #define SQUARE(x) (x*x) creates calculates the square of x. A function is a type of subprogram that can be called from any other function in the program to carry out a specific task. For instance, the function int square(int x) return x*x; defines how to find the square of x. A macro does not perform type checking before it is executed at compile time, which could result in errors or inefficiency. At runtime, a function performs type checking to guarantee correctness and safety.