#include<stdio.h>
int main()
{
int i = 11;
int *p = &i;
foo(&p);
printf("%d ", *p);
}
void foo(int *const *p)
{ int j = 10;
*p = &j;
printf("%d ", **p);
}
//it showed compile time error. Can anyone please explain
#include<stdio.h>
int main()
{
int i = 11;
int *p = &i;
foo(&p);
printf("%d ", *p);
}
void foo(int *const *p)
{ int j = 10;
*p = &j;
printf("%d ", **p);
}
//it showed compile time error. Can anyone please explain
int *const *p
p
is a pointer to a constant pointer to int
.
You can change p
itself;
You cannot change *p
;
You can change **p
.
void foo(int *const *p)
{ int j = 10;
*p = &j; // nope
printf("%d ", **p);
}
In your code you defined the method after calling it, so you should place it before main()