Free tutorials & notes in Hindi & English · Clean code examples · Mobile friendly learning
Free tutorials in Hindi & English Daily computer, mobile and IT guides Beginner friendly learning
Blog · C Programming · 03 Jul 2026 · Hindi + English

C में const और #define में अंतर (Comparison Table के साथ)

const एक typed, scoped read-only variable है जबकि #define compilation से पहले replace होने वाला textual macro है. 6 अंतर की पूरी comparison table.

const vs #define: the core idea

One-line answer: const creates a real, typed, read-only variable checked by the compiler, while #define is a plain text replacement done by the preprocessor before compilation even starts.
const int MAX = 100;    /* compiler: typed read-only variable */
#define MAX 100         /* preprocessor: text replacement     */

Comparison table: 6 key differences

Pointconst#define
Handled byCompilerPreprocessor (before compilation)
Data typeYes — type checking worksNo type — just text
ScopeFollows block/function/file scopeActive from #define line till end of file (or #undef)
MemoryUsually occupies memory, has an addressNo memory, no address
Debugger visibilityVisible with its nameInvisible — already replaced by value
Usable in case labels / #ifNo (in C)Yes

Program showing the difference

#include <stdio.h>

#define TAX 18          /* text replacement */

int main() {
    const int limit = 500;    /* typed variable */

    printf("Address of limit: %p\n", (void*)&limit);  /* OK   */
    /* printf("%p", &TAX); */  /* ERROR: TAX has no address  */

    switch (18) {
        case TAX:  printf("Tax slab matched\n"); break;  /* OK        */
        /* case limit: */      /* ERROR: not a constant expression in C */
    }
    return 0;
}
Address of limit: 0x7ffd2c... Tax slab matched

The classic #define trap

#define SQUARE(x) x * x

int main() {
    int r = SQUARE(2 + 3);   /* expands to: 2 + 3 * 2 + 3 = 11, not 25! */
    return 0;
}
Because #define is blind text replacement, SQUARE(2 + 3) becomes 2 + 3 * 2 + 3 = 11. const values never suffer from this because they are real evaluated values, not text. (Fix for macros: #define SQUARE(x) ((x)*(x)).)

When to use which?

  • Use const for typed values: const double RATE = 8.5; — you get type checking, scoping and debugger support.
  • Use #define when you need a value in case labels, array sizes on very old compilers, or conditional compilation like #if VERSION > 2.
  • In modern C, the general rule taught in interviews is: "Prefer const over #define for constants; use #define only where const cannot work."

const vs #define: core idea

One-line answer: const एक real, typed, read-only variable बनाता है जिसे compiler check करता है, जबकि #define plain text replacement है जो compilation शुरू होने से पहले preprocessor करता है.
const int MAX = 100;    /* compiler: typed read-only variable */
#define MAX 100         /* preprocessor: text replacement     */

Comparison table: 6 मुख्य अंतर

Pointconst#define
Handle कौन करता हैCompilerPreprocessor (compilation से पहले)
Data typeहां — type checking काम करती हैकोई type नहीं — सिर्फ text
ScopeBlock/function/file scope follow करता है#define line से file के अंत तक active (या #undef तक)
Memoryआमतौर पर memory लेता है, address होता हैन memory, न address
Debugger में दिखनाName के साथ दिखता हैनहीं दिखता — पहले ही value से replace हो चुका
case labels / #if में useनहीं (C में)हां

अंतर दिखाने वाला program

#include <stdio.h>

#define TAX 18          /* text replacement */

int main() {
    const int limit = 500;    /* typed variable */

    printf("Address of limit: %p\n", (void*)&limit);  /* OK   */
    /* printf("%p", &TAX); */  /* ERROR: TAX का कोई address नहीं */

    switch (18) {
        case TAX:  printf("Tax slab matched\n"); break;  /* OK        */
        /* case limit: */      /* ERROR: C में constant expression नहीं */
    }
    return 0;
}
Address of limit: 0x7ffd2c... Tax slab matched

#define का classic trap

#define SQUARE(x) x * x

int main() {
    int r = SQUARE(2 + 3);   /* बनता है: 2 + 3 * 2 + 3 = 11, 25 नहीं! */
    return 0;
}
#define blind text replacement है, इसलिए SQUARE(2 + 3) बन जाता है 2 + 3 * 2 + 3 = 11. const values के साथ यह problem कभी नहीं आती क्योंकि वे real evaluated values हैं, text नहीं. (Macro का fix: #define SQUARE(x) ((x)*(x)).)

कब कौन-सा use करें?

  • const use करें typed values के लिए: const double RATE = 8.5; — type checking, scoping और debugger support मिलता है.
  • #define use करें जब value case labels, बहुत पुराने compilers पर array sizes, या #if VERSION > 2 जैसी conditional compilation में चाहिए.
  • Modern C में interviews में यही rule सिखाया जाता है: "Constants के लिए const prefer करें; #define सिर्फ वहां use करें जहां const काम नहीं कर सकता."

Frequently Asked Questions

C में const और #define में main अंतर क्या है?

const एक typed read-only variable है जिसे compiler scope और type checking के साथ process करता है, जबकि #define compilation से पहले preprocessor द्वारा किया गया untyped text replacement है.

क्या #define memory लेता है?

नहीं. #define कोई variable नहीं बनाता, इसलिए यह memory नहीं लेता और इसका कोई address नहीं होता; value सीधे code में paste हो जाती है.

क्या C में const को switch case label में use कर सकते हैं?

नहीं. C में const variable constant expression नहीं होता, इसलिए case labels के लिए #define macros, enum constants या literals चाहिए.