CKTIS / C++
T* pointer declarator
The `T*` declarator forms the type “pointer to T”. In `int* p = &value;`, `p` holds a pointer to `value`, not a copy of that integer. The position of `const` determines whether the restriction applies to the pointed-to object or to the pointer itself.
Version: C++23; repository compiler flag, production runtime not attested
Syntax
T* p = &object;
T* p = nullptr;
const T* p = &object;
T* const p = &object;In the declaration T* p, * is part of the declarator: it declares p as a pointer to T. It does not create a T object. In int* p = &value;, the expression &value takes the address of an existing object. In contrast, *p in an expression means dereferencing, or accessing the pointed-to object—a different use of the same symbol.
Each declarator is analyzed separately: int* p, n; declares a pointer p and an integer n. To declare two pointers, write int *p, *q; or use separate declarations. Whitespace around * does not change the meaning.
const int* p allows changing p but forbids modifying the integer through *p. int* const p prevents changing the pointer value after initialization but allows modifying the pointed-to integer. const int* const p combines both restrictions. In the example, readOnly observes changes made through fixed: a pointer to const does not guarantee that the object cannot change through another route.
Initialize a pointer with a valid address or nullptr. Do not dereference a null pointer; before reading or writing through a pointer, ensure that it points to an appropriate object whose lifetime has not ended. A pointer declaration alone does not ensure the pointed-to object's lifetime.
This entry targets C++23. The supplied source is an evolving working draft, not a frozen C++23 publication. The compiler flag supports planned local verification; it does not attest production runtime behavior.
Examples
#include <iostream>
int main() {
int value = 7;
int* p = &value;
*p = 12;
const int* readOnly = p;
int* const fixed = &value;
*fixed += 3;
std::cout << value << ' ' << *readOnly << '\n';
}
Result
15 15
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.