+ 5
Difference between char* const p and char const *p??
4 Réponses
+ 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
}
+ 3
thanks himani
+ 1
There is no functional difference, they are both the same
+ 1
aklex Jamie thanks