Saturday, July 6, 2013

pointer const

code 1:

void fun(const int **);

int main()
{
int **p;

fun(p);
}


code 2:

void fun(const int **);

int main()
{
const int **p;

fun(p);
}


code 1 is compile error and 2 is not. can you explain why ? as per my knowledge, we can convert a non-const to const but we cant change const to non-const. and even to prove this, when i repace the above with "pointer to int" and everything remain same, then it works. then what is hidden in double pointer conversion fron int ** to const int **. thanks in advance. - Full Post

No comments:

Post a Comment