Answer:
Constant pointer is pointer which points a fixed object. For example:
int i=10;
int * const p=&i;
Here p is constant pointer which is pointing to variable i. After the initialization statement pointer p cannot points any other variable. For example:
#include<stdio.h>
void main(){
int i=10,j=20;
int * const p=&i;
p=&j //cannot modify const pointer
printf("%d",*p);
}
Output: Compilation error
But we can modify the content of any const pointer. For example:
#include<stdio.h>
void main(){
int i=10;
int * const p=&i;
*p=25;
printf("%d",i);
}
Output: 25
No comments:
Post a Comment