+ 2

How do the statements differ? char * const p; char const *p;

26th Oct 2017, 10:57 AM
Aindrila Rakshit
2 ответов
+ 4
char*const p; // it declares a constant pointer p . Here you can't make any changes in the pointer variable p but you can make changes in the variable it is pointing to, even if it is a constant variable.( using (*p) ) Ex: main() { const char x= á; char const *p; p=&x; // error ++(*p); //no error p++; // error } char const *p; // it declares a pointer which can point to a constant variable. Here you can make changes in the pointer variable p but you can't make any changes in the variable it is pointing to. Ex: main() { const char x= á; char const *p; p=&x; //no error ++(*p); //error p++; //no error }
7th Jan 2018, 12:38 PM
Himani
- 3
I think first one is invalid isn't it?
28th Oct 2017, 4:57 AM
#RahulVerma
#RahulVerma - avatar