Interview Question

What is const?

const restricts modification through a qualified access path.

💡 Concept ✅ Quick Revision ⚙ C

Answer

const qualifies a type so an object cannot be modified through that qualified lvalue. • It does not always mean the underlying object can never change through another valid non-const access path. • A pointer and its pointed-to type can be qualified separately. • Casting away const and modifying an object originally defined as const has undefined behavior.

💡 C Example

int value = 10; const int *pointer = &value; value = 20; printf("%d\n", *pointer);

Output

20

⚡ Quick Revision

const restricts modification through a qualified access path.