Preprocessor Directives
Definition:
These are commands that are processed before actual compilation. They begin with #.
Common Directives:
|
Directive |
Description |
|
#include |
Includes standard/library files |
|
#define |
Defines macros/constants |
|
#ifdef / #ifndef |
Conditional compilation |
|
#undef |
Undefines a macro |
|
#pragma |
Special compiler instructions |
Example
#include <stdio.h>
#define PI 3.14
int main() {
printf(“Value of PI: %f\n”, PI);
return 0;
}
Tips & Best Practices
- Always initialize variables.
- Use meaningful variable and function names.
- Avoid using too many goto statements.
- Comment your code for clarity.
- Prefer functions to break down complex code.
- Always free() dynamically allocated memory.
- Validate user input wherever necessary.