+ 2
How do the statements differ? char * const p; char const *p;
2 Respostas
+ 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
}
- 3
I think first one is invalid
isn't it?