C ++ const constant pointer

If you find content Benpian does not suit you, you can see the C ++ pointer directory

In the last chapter , we learned that the C ++ pointer common usage

In this chapter, we need to learn to skillfully use const , before they can enter the following sections, can not familiar look: C ++ const usage

 

Well, that is entered, now use some general pointers, but do not know if you have not thought about:

If a pointer is const how to do?

 

When we declare a const pointer, there are two writing: ( character pointer exception)

const  int * p;

or

int* const p;

Both methods equivalent

 

: We need to know initialize const pointer allows open space, but does not allow additional initialization, you must open up space or declaration

 

That is like this:

 

const int* p=nullptr;
p=new int[N];

 

or

const int* p=new int[N];

That is, if we write is wrong of:

const int* p=new int[N];
p[0]=0;//Error!!!

 

The main usage of const pointer has been finished, it is recommended to enter the next chapter: structure and class pointers

It is also recommended to see other pointers knowledge: C ++ pointer directory

 

Guess you like

Origin www.cnblogs.com/tweechalice/p/11443632.html
Recommended