const pointer cannot be passed to non-const parameter.
In line :fun(&ptr);
ptr in non-const, but argument required is const **ptr .
Indu said:
(Fri, Aug 5, 2011 03:21:53 PM)
Can Anyone Explain?
Ranjit said:
(Tue, Aug 23, 2011 08:17:19 AM)
Ravi already said it.
Ptr is a const pointer. The argument of fun should be const too.
Am12Cs said:
(Wed, Aug 31, 2011 10:27:46 PM)
#include<stdio.h>
int fun(int **ptr);
int main()
{
int i=10;
const int *ptr = &i;{{Probably CONST INT*PTR IS ASSIGNED TO REFERENCE OF 'I' WHICH CNT BE ALTERED BUT PTR IN FUTURE CAN BE ASSIGNED SOMETHING ELSE WHICH WILL NOT GIVE AN ERROR.
const int *ptr = &i;
*PTR=12;//ERROR
ptr=10;//NO ERROR
const int *ptr = &i;
int fun(int **ptr)
{
int j = 223;
int *temp = &j;
printf("Before changing ptr = %5x\n", *ptr);
const *ptr = temp;// HERE IS THE ERROR
printf("After changing ptr = %5x\n", *ptr);
return 0;
}
}
Bond said:
(Thu, Sep 8, 2011 12:31:08 AM)
The ptr is declared twice in the function. How come that is not an error?