devxlogo

Pointer to a Constant vs. Constant Pointer

The const keyword in C++ provides a type-safe way to replace some of those #define preprocessor statements that you’re used to writing from C.Whenever you have a value that you do not wish to have changed, you should declare it as const. For example:

 const int i = 12; // any further attempt to alter i will cause an error.

However, when pointers are involved, what is actually constant depends on where you place the const keyword. Also, the syntax can be slightly confusing.

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.