Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Unit 2 — Preprocessor Directives

Lesson 10 of 32 in the free C Language notes on Siksha Sarovar, written by Rohit Jangra.

Preprocessor Directives in C

The C Preprocessor processes source code before compilation. Directives start with # and are not C statements (no semicolon needed).

---

1. #include

Includes the contents of another file.

#include <stdio.h>    /* system header (angle brackets) */
#include "myfile.h"   /* user-defined header (quotes) */

---

2. #define — Macro Definition

Object-like Macros (Constants)

#define PI 3.14159
#define MAX_SIZE 100
#define TRUE 1
#define FALSE 0

float area = PI * r * r;

Function-like Macros

#define SQUARE(x) ((x) * (x))
#define MAX(a, b) ((a) > (b) ? (a) : (b))

int s = SQUARE(5);       /* expands to ((5) * (5)) = 25 */
int m = MAX(3, 7);       /* expands to 7 */
Note: Always parenthesise macro arguments to avoid operator precedence bugs.

---

3. #undef — Undefine a Macro

#define LIMIT 10
/* ... */
#undef LIMIT    /* LIMIT is no longer defined */

---

4. Conditional Compilation

#ifdef / #ifndef / #endif

#define DEBUG

#ifdef DEBUG
    printf("Debug mode on\n");
#endif

#ifndef RELEASE
    printf("Not a release build\n");
#endif

#if / #elif / #else / #endif

#define VERSION 2

#if VERSION == 1
    printf("Version 1");
#elif VERSION == 2
    printf("Version 2");
#else
    printf("Unknown version");
#endif

---

5. #pragma

Compiler-specific instructions.

#pragma once         /* include file only once (non-standard but widely supported) */
#pragma warning(disable: 4996)  /* suppress a specific warning */

---

6. Predefined Macros

MacroExpands to
FILEName of current file
LINECurrent line number
DATECompilation date
TIMECompilation time
STDC1 if ANSI C standard
printf("File: %s, Line: %d\n", __FILE__, __LINE__);