This was about the introduction and how .c and .cpp compiler treated the const. Now I would like to go deep into what does const means in cpp and what are the combination you can use with the object pointer and how the complicated the situation can become.
const int *p
int const *p
int * const p
const * int p // Warning
* const int p // Error
* int const p // Error
Lets take each one of them and see what it means how it behaves
const int *p & int const *p
Read it as "Pointer to constant int". For how to read it refer to the last section of the article, How to read. Now the expression means its a pointer pointing to the constant value.
As an example
cout<<"Pointer to constant int";{ int i = 123; const int * p = &i; cout <<"p = i = "<<*p<
Code: CPP
cout<<"Constant pointer"<
int * const p means "p is a const pointer to an int"
No comments:
Post a Comment