A structured lesson workspace with readable content, hands-on examples, and a clean path to completion.
const int *p and int * const p are different declarations with different meanings. The first is a pointer to a constant int: you can change where p points, but you cannot modify the int through p. The second is a constant pointer to int: p always points to the same address, but you can modify the int it points to. The position of const relative to the * determines what is constant. Reading these declarations correctly is a basic literacy skill in C.
#include <stdio.h>int main(void) {int x = 10;int y = 20;const int *ptr_to_const = &x;printf("ptr_to_const -> %d\n", *ptr_to_const);ptr_to_const = &y;printf("ptr_to_const -> %d (repointed OK)\n", *ptr_to_const);int *const const_ptr = &x;printf("const_ptr -> %d\n", *const_ptr);*const_ptr = 99;printf("const_ptr -> %d (modified OK)\n", *const_ptr);const int *const both_const = &x;printf("both_const -> %d\n", *both_const);return 0;}
Read C declarations right-to-left from the identifier. const int *p: start at p, go right (nothing), go left (*: pointer to), go right again (nothing), go left (const int: constant int). Result: p is a pointer to a constant int. int *const p: start at p, go right (nothing), go left (const: constant), go right (*: pointer to), go left (int). Result: p is a constant pointer to int. The const binds to whatever is immediately to its left, unless it is at the far left, in which case it binds to the right.
#include <stdio.h>int main(void) {int x = 10;int y = 20;const int *ptr_to_const = &x;*ptr_to_const = 99;int *const const_ptr = &x;const_ptr = &y;return 0;}
Two errors. The first: you cannot write through a pointer-to-const. The second: you cannot reassign a const pointer. The compiler enforces both. These are not warnings. They are hard errors. The const qualifier is a contract, and the compiler is the enforcer.
This distinction appears in every C API. strlen takes const char * because it does not modify the string. strcpy takes char * for the destination because it does. Reading the const placement tells you the function's contract without reading the documentation. Next: array vs &array, a subtle pointer difference that matters in multi-dimensional contexts.
Finish the lesson once you have worked through the material. This awards ★ 30 XP.