Answer in brief
The preprocessor handles directives and macro replacement as part of translating C source. A directive normally begins with # after any leading whitespace.
Main directives
- #include makes header contents available for preprocessing.
- #define creates an object-like or function-like macro.
- #undef removes a macro definition.
- #if, #ifdef, #ifndef, #elif, #else and #endif control which source text is included.
- #error requests a diagnostic when a required configuration is missing or invalid.
Header inclusion
Use #include <stdio.h> for the standard input/output declarations. Quoted inclusion, such as #include "settings.h", is commonly used for project headers. The implementation defines the precise search rules. Including a header is not the same as copying the compiled implementation of every library function into the program.
Example explanation
The sample defines LIMIT as 3. During preprocessing, uses of the macro name are replaced by its replacement tokens. The resulting loop prints 1, 2 and 3. The macro is not an ordinary int variable and does not have a separate object storing 3.
Why it is useful
Headers support shared declarations. Macros can name configuration values, and conditional compilation can choose platform or debug code. These operations affect the translated source; an ordinary runtime if instead makes a decision while the program is running.
Important points
Do not put a semicolon after a simple numeric macro unless a semicolon is intentionally part of the replacement. Macros are not checked like typed function parameters. Inspect expanded expressions carefully, especially when arithmetic operators or repeated arguments are involved.
C program and output
/* CodeBhavya | PPS AR25 | Learning example */
#include <stdio.h>
#define LIMIT 3
int main(void)
{
for (int i = 1; i <= LIMIT; ++i) { printf("%d\n", i); }
return 0;
}
Sample input and output
This example uses values already written in the program.
Output
1
2
3