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

Top 15 const Interview Questions in C with Answers

15 most-asked const interview questions in C with clear answers: const vs #define, const pointers, const correctness, volatile const and tricky outputs.

How to use this list

These 15 questions cover every const topic asked in campus placements, viva and technical interviews — from one-line definitions to tricky output questions. Read the question, try to answer mentally, then check.

Basic questions (1–5)

Q1. What is const in C?

const is a type qualifier that makes a variable read-only after initialization. Any attempt to modify it is a compile-time error.

Q2. Can a const variable be declared without initialization?

Syntactically yes, but it is useless and wrong in practice: it locks a garbage value forever, because assignment after declaration is an error. Always initialize const at declaration.

Q3. What error do you get on modifying a const?

GCC reports: error: assignment of read-only variable 'x'. The keyword to say in interviews is "read-only".

Q4. Does a const variable occupy memory?

Yes. Unlike #define, a const variable is a real object with an address — you can apply & to it and sizeof works normally.

Q5. Is const the same in C and C++?

No. In C++ a const int initialized with a literal is a true compile-time constant (usable in array sizes and case labels). In C it is only a read-only runtime object.

const vs #define (6–8)

Q6. Difference between const and #define?

const: compiler-handled, typed, scoped, has memory, debugger-visible. #define: preprocessor text replacement, no type, no scope, no memory. Prefer const; use #define for case labels and #if.

Q7. Why is #define SQUARE(x) x*x dangerous?

SQUARE(2+3) expands to 2+3*2+3 = 11, not 25, because it is blind text replacement. Correct macro: ((x)*(x)). const/functions never have this problem.

Q8. Can const be used in a case label in C?

No — a const variable is not a constant expression in C. Use #define, enum or a literal.

const and pointers (9–12)

Q9. Difference between const int *p and int *const p?

const int *p: value locked, pointer movable. int *const p: pointer locked to one address, value modifiable. Trick: read right to left.

Q10. What is const int *const p?

A const pointer to const data — neither the address nor the value can change. Only reading is allowed.

Q11. Why do library functions use const char * parameters?

It is a compiler-enforced promise that the function will not modify the caller's string — this is called const correctness.

Q12. Can we modify a const through a normal pointer cast?

The compiler may allow the cast, but writing through it is undefined behaviour — the value may live in read-only memory and the program can crash.

Advanced / tricky (13–15)

Q13. What is const correctness?

A design discipline: mark every pointer/parameter that should not modify data as const, so the compiler catches accidental writes across the whole codebase.

Q14. Can const and volatile be used together?

Yes: const volatile int *status; — the program must not write to it (const) but the value may change externally, e.g. a hardware register (volatile). Classic embedded-systems question.

Q15. Predict the output:

const int x = 5;
int *p = (int*)&x;
*p = 10;
printf("%d %d", x, *p);

Answer: undefined behaviour. Many compilers print "5 10" (x optimized as 5), some print "10 10", some crash. The correct interview answer is: "The behaviour is undefined; modifying a const object through a cast is illegal."

इस list को कैसे use करें

ये 15 questions campus placements, viva और technical interviews में पूछे जाने वाले हर const topic को cover करते हैं — one-line definitions से tricky output questions तक. Question पढ़ें, मन में answer try करें, फिर check करें.

Basic questions (1–5)

Q1. C में const क्या है?

const एक type qualifier है जो variable को initialization के बाद read-only बना देता है. Modify करने की कोई भी कोशिश compile-time error है.

Q2. क्या const variable बिना initialization के declare हो सकता है?

Syntax के हिसाब से हां, लेकिन practically useless और गलत: garbage value हमेशा के लिए lock हो जाती है, क्योंकि declaration के बाद assignment error है. const को हमेशा declaration पर initialize करें.

Q3. const modify करने पर कौन-सा error आता है?

GCC देता है: error: assignment of read-only variable 'x'. Interview में बोलने वाला keyword है "read-only".

Q4. क्या const variable memory लेता है?

हां. #define के उलट, const variable एक real object है जिसका address होता है — उस पर & लगा सकते हैं और sizeof normally काम करता है.

Q5. क्या const C और C++ में same है?

नहीं. C++ में literal से initialize किया गया const int true compile-time constant है (array sizes और case labels में usable). C में यह सिर्फ read-only runtime object है.

const vs #define (6–8)

Q6. const और #define में अंतर?

const: compiler-handled, typed, scoped, memory लेता है, debugger में दिखता है. #define: preprocessor text replacement, न type, न scope, न memory. const prefer करें; case labels और #if के लिए #define.

Q7. #define SQUARE(x) x*x खतरनाक क्यों है?

SQUARE(2+3) बन जाता है 2+3*2+3 = 11, 25 नहीं, क्योंकि यह blind text replacement है. सही macro: ((x)*(x)). const/functions में यह problem कभी नहीं आती.

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

नहीं — C में const variable constant expression नहीं है. #define, enum या literal use करें.

const और pointers (9–12)

Q9. const int *p और int *const p में अंतर?

const int *p: value locked, pointer movable. int *const p: pointer एक address पर locked, value modifiable. Trick: right से left पढ़ें.

Q10. const int *const p क्या है?

const data का const pointer — न address change हो सकता है, न value. सिर्फ reading allowed है.

Q11. Library functions const char * parameters क्यों use करते हैं?

यह compiler-enforced promise है कि function caller की string modify नहीं करेगा — इसे const correctness कहते हैं.

Q12. क्या normal pointer cast से const modify कर सकते हैं?

Compiler cast allow कर सकता है, लेकिन उससे write करना undefined behaviour है — value read-only memory में हो सकती है और program crash हो सकता है.

Advanced / tricky (13–15)

Q13. const correctness क्या है?

एक design discipline: हर वह pointer/parameter जो data modify नहीं करना चाहिए, उसे const mark करें, ताकि compiler पूरे codebase में accidental writes पकड़ ले.

Q14. क्या const और volatile साथ use हो सकते हैं?

हां: const volatile int *status; — program उस पर write नहीं कर सकता (const) लेकिन value externally change हो सकती है, जैसे hardware register (volatile). Classic embedded-systems question.

Q15. Output predict करें:

const int x = 5;
int *p = (int*)&x;
*p = 10;
printf("%d %d", x, *p);

Answer: undefined behaviour. कई compilers "5 10" print करते हैं (x को 5 optimize कर देते हैं), कुछ "10 10", कुछ crash. सही interview answer है: "Behaviour undefined है; cast से const object modify करना illegal है."

Frequently Asked Questions

What is the most asked const interview question?

The difference between const int *p (pointer to const) and int *const p (const pointer) is the single most asked const question in C interviews.

What is const correctness?

const correctness means consistently marking all data that should not be modified as const, so the compiler enforces read-only access throughout the program.

Can const and volatile appear together?

Yes. const volatile is used for values the program must not write but which can change externally, like hardware status registers.