Difference between constant pointer, pointers to constant, and constant pointers to constants

Last Updated : 14 Jul, 2026

Pointers in C can be qualified using the const keyword to control whether the pointer or the data it points to can be modified.

  • The three common types are pointer to constant, constant pointer, and constant pointer to constant.
  • Each type provides a different level of protection for the pointer, the pointed data, or both.

Pointers to constant

In the pointers to constant, the data pointed by the pointer is constant and cannot be changed. Although, the pointer itself can change and points somewhere else (as the pointer itself is a variable).

C++
#include <iostream>
using namespace std;

// Driver Code
int main()
{

    int high{ 100 };
    int low{ 66 };
    const int* score{ &high };

    // Pointer variables are read from
    // the right to left
    cout << *score << "\n";

    // Score is a pointer to integer
    // which is constant *score = 78

    // It will give you an Error:
    // assignment of read-only location
    // ‘* score’ because value stored in
    // constant cannot be changed
    score = &low;

    // This can be done here as we are
    // changing the location where the
    // score points now it points to low
    cout << *score << "\n";

    return 0;
}

Output
100
66

Constant pointers

A constant pointer is a pointer that always points to the same memory location, but the value stored at that location can be modified.

  • The pointer address cannot be changed after initialization because the pointer itself is constant.
  • It is similar to a reference in that it always refers to the same variable, while allowing the variable's value to be updated.

C++
#include <iostream>
using namespace std;

// Driver Code
int main()
{

    int a{ 90 };
    int b{ 50 };

    int* const ptr{ &a };
    cout << *ptr << "\n";
    cout << ptr << "\n";

    // Address what it points to

    *ptr = 56;

    // Acceptable to change the
    // value of a

    // Error: assignment of read-only
    // variable ‘ptr’
    // ptr = &b;

    cout << *ptr << "\n";
    cout << ptr << "\n";

    return 0;
}

Output
90
0x7ffc641845a8
56
0x7ffc641845a8

Constant Pointers to constants

A constant pointer to a constant is a pointer whose address cannot be changed, and the value it points to cannot be modified.

  • Both the pointer and the pointed data remain constant after initialization.
  • It is useful when both the memory address and the stored value must remain unchanged throughout the program.

C++
#include <iostream>
using namespace std;

// Driver Code
int main()
{

    const int a{ 50 };
    const int b{ 90 };

    // ptr points to a
    const int* const ptr{ &a };

    // *ptr = 90;
    // Error: assignment of read-only
    // location ‘*(const int*)ptr’

    // ptr = &b;
    // Error: assignment of read-only
    // variable ‘ptr’

    // Address of a
    cout << ptr << "\n";

    // Value of a
    cout << *ptr << "\n";

    return 0;
}

Output
0x7ffea7e22d68
50
Comment