Pointers and const

Rule: ✅ const binds to left side; if none, binds to right.


1) Pointer to const (data const)

int a=10,b=20;
const int *p = &a;
p = &b;   // ✅
*p = 5;   // ❌

2) Const pointer (pointer const)

int * const p = &a;
*p = 5;  // ✅
p = &b;  // ❌

3) Const pointer to const data

const int * const p = &a;

Both cannot change.


Summary table

Declaration Change pointer? Change data?
const int *p ✅ yes ❌ no
int *const p ❌ no ✅ yes
const int *const p ❌ no ❌ no

Reading trick (right to left)