---
title: "Explain pointer to the constant and constant pointer ?"  
description: "Explain pointer to the constant and constant pointer ?"  
author: "James Smith"  
published: 2011-07-23  
updated: 2020-09-15  
canonical: https://www.mindstick.com/interview/1103/explain-pointer-to-the-constant-and-constant-pointer  
category: "visual c++"  
tags: ["visual c++"]  
reading_time: 2 minutes  

---

# Explain pointer to the constant and constant pointer ?

Pointer to constant does not allow to change the value at the address pointed by pointer ( *ptr).\
\
1. const int *ptr = 3;\
2. int const *ptr; // 1 and 2 both are having same meaning.\
\
*ptr = 5; // not allowed\
\
Constant pointer does not allow to change the address to which pointer is pointing.\
int i = 10;\
int * const ptr = &i;\
int j =80;\
\
ptr = &j; // not allowed.\
\
\
constant pointer to constant data\
int i = 9;\
const int * const ptr = &i;\
int j =90;\
\
*ptr =10; // not allowed\
ptr = &j; // not allowed.\
\
\

## Answers

### Answer by James Smith

Pointer to constant does not allow to change the value at the address pointed by pointer ( *ptr).\
\
1. const int *ptr = 3;\
2. int const *ptr; // 1 and 2 both are having same meaning.\
\
*ptr = 5; // not allowed\
\
Constant pointer does not allow to change the address to which pointer is pointing.\
int i = 10;\
int * const ptr = &i;\
int j =80;\
\
ptr = &j; // not allowed.\
\
\
constant pointer to constant data\
int i = 9;\
const int * const ptr = &i;\
int j =90;\
\
*ptr =10; // not allowed\
ptr = &j; // not allowed.\
\
\


---

Original Source: https://www.mindstick.com/interview/1103/explain-pointer-to-the-constant-and-constant-pointer

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
