What\'s the difference between:
char * const
and
const char *
Syntax:
datatype *const var;
char *const
comes under this case.
/*program to illustrate the behaviour of constant pointer */
#include
int main(){
int a=10;
int *const ptr=&a;
*ptr=100;/* we can change the value of object but we cannot point it to another variable.suppose another variable int b=20; and ptr=&b; gives you error*/
printf("%d",*ptr);
return 0;
}
Syntax:
const datatype *var
or datatype const *var
const char*
comes under this case.
/* program to illustrate the behavior of pointer to a constant*/
#include
int main(){
int a=10,b=20;
int const *ptr=&a;
printf("%d\n",*ptr);
/* *ptr=100 is not possible i.e we cannot change the value of the object pointed by the pointer*/
ptr=&b;
printf("%d",*ptr);
/*we can point it to another object*/
return 0;
}