The use of pointers and const qualifier in C++ is an important core of memory management and code safety. While pointers allow developers to manipulate memory addresses directly, they also introduce complications regarding data modification, so it is important to know the difference between the various pointers. In this article, we will discuss the difference between const int*, const int * const, and int * const.
Table of Contents:
What are the const int*, const int * const, and int * const in C++?
In C++, there are three types of pointers, which are: const int*, const int* const, and int* const. They treat the const keyword differently than the modifiers that can be applied to a pointer or elements of an array to which that same pointer refers.
Difference between const int*, const int * const, and int * const in C++
In C++, const int*, const int* const, and int* const represent different pointer types with different constraints on mutability. The main differences lie in whether the pointer itself or the value it points to can be modified. Below, you can find the main differences between these pointers.
1. const int* (Pointer to Constant Integer)
A const int* is a pointer to an integer constant that restricts modifying the integer value to which it points through the same pointer. However, the pointer being changed now can have a different memory location to point to.
Properties:
- The pointer can be changed, which means that it can point to another variable.
- Value cannot be changed (cannot modify the integer through this pointer).
Example:
Output:

The code shows the use of a const int* pointer that points to an integer, allowing the pointer to be reassigned to a different integer while preventing modification of the integer value it points to.
2. const int* const (Constant Pointer to Constant Integer)
A const int* const is a constant pointer to a constant integer, which means that neither the pointer nor the value it points to can be modified.
Properties:
- The pointer cannot be changed, thus, it must always point to the same variable.
- The value cannot be changed (read-only access to the integer).
Example:
Output:

The code shows how a const int* const pointer is defined that permanently points to an integer without allowing modification of the pointer or the integer’s value.
3. int* const (Constant Pointer to Integer)
An int* const is a constant pointer to an integer, which means that the pointer must always point to the same memory address, but the value it points to can be modified.
Properties:
- The pointer cannot be changed, thus, it must always point to the same variable.
- The value can be changed (modifiable through the pointer).
Example:
Output:

The code shows how to use an int* const pointer that allows modification of the pointed integer’s value while keeping the pointer itself fixed to the same address.
const int* vs const int * const vs int * const
Pointer Type | Value Modification | Pointer Reassignment | Must be Initialized at Declaration? |
const int* | Not Allowed | Allowed | No |
const int* const | Not Allowed | Not Allowed | Yes |
int* const | Allowed | Not Allowed | Yes |
Conclusion
It is important to understand that using these types of pointers creates differences for memory management and code safety in the language of C++. Each pointer type has its own endpoint, properties, and ability to modify, depending on the data it points to. When they are used correctly, pointer types can avoid creating immutability where it is not necessary, protect against unintended modifications, and improve code clarity and reliability.
Difference between const int*, const int * const, and int * const – FAQs
1. What is the difference between const int* and int* const?
The difference between const int* and int* const is that const int* allows changes to the pointer but does not allow changes to the value that the pointer points to, while int* const allows changing the value but not the pointer that points to that value itself.
2. Can I reassign a const int* const pointer?
No, A const int* const pointer cannot be reassigned or modified.
3. When should I use int* const?
Use int* const when the address should have remained fixed, and the value it points to can be modified.
4. What happens if I modify a constant value through a pointer?
The compiler will throw an error since you cannot modify a constant value.
5. How do these pointer types affect function parameters?
These different pointer types indicate different levels of access: const int* for read-only, const int* const for totally immutable, and int* const for changing value without pointer reassignment.