+ 5

Difference between char* const p and char const *p??

3rd Dec 2017, 3:24 PM
Aman Raj
Aman Raj - avatar
4 Antworten
+ 9
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:55 PM
Himani
+ 3
thanks himani
7th Jan 2018, 4:19 PM
Aman Raj
Aman Raj - avatar
+ 1
There is no functional difference, they are both the same
3rd Dec 2017, 3:31 PM
aklex
aklex - avatar
+ 1
aklex Jamie thanks
4th Dec 2017, 10:45 AM
Aman Raj
Aman Raj - avatar