What is const pointer?
Submitted by: Administratorconst pointer is a pointer which you don't want to be pointed to a different value. That is, the location stored in the pointer can not change. We can not change where the pointer points. It is declared as:
type * const name
type is data type
name is name of the pointer
eg: char * const p
Since the location to which a const pointer points to can not be changed, the following code:
char ch1 = ‘A';
char ch2 = ‘B';
char * const p = &ch1;
p = &ch2;
will throw an error since address stored in p can not be changed.
Submitted by: Administrator
type * const name
type is data type
name is name of the pointer
eg: char * const p
Since the location to which a const pointer points to can not be changed, the following code:
char ch1 = ‘A';
char ch2 = ‘B';
char * const p = &ch1;
p = &ch2;
will throw an error since address stored in p can not be changed.
Submitted by: Administrator
Read Online C++ Pointers & Functions Job Interview Questions And Answers
Top C++ Pointers & Functions Questions
☺ | Can you please explain the difference between Pointer to constant and pointer constant? |
☺ | How many minimum number of functions are need to be presented in c++? |
☺ | Explain function pointers? |
☺ | Explain pointer with examples? |
Top C Plus Plus Language Categories
☺ | C++ Pointers & Functions Interview Questions. |
☺ | C++ Operator Overloading Interview Questions. |
☺ | C++ Exception Handling Interview Questions. |
☺ | C++ Template Interview Questions. |
☺ | C++ Virtual Functions Interview Questions. |