What is a macro in C?

What is a macro in C?

a) A preprocessor directive that defines a piece of code that can be reused
b) A variable that stores a floating-point value
c) A function that returns a pointer
d) A memory location

Answer:

a) A preprocessor directive that defines a piece of code that can be reused

Explanation:

A macro in C is a preprocessor directive that defines a piece of code that can be reused multiple times throughout a program. Macros are defined using the #define directive, and they can represent constant values, expressions, or even entire blocks of code. When the preprocessor encounters a macro, it replaces the macro with its defined content before the code is compiled. Macros can make code more readable and easier to maintain, but they should be used carefully as they do not provide type checking or scope restrictions.

Understanding macros is crucial for efficient code reuse and avoiding repetitive code in C programs.

Reference links:

https://www.rameshfadatare.com/learn-c-programming/

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top