Hi,
Kindly see the snippet below
In this p is constant and not the value pointed to by p;Code:
typedef int *ptr;
const ptr p;
Suppose if we want to make the value pointed to by p, a constant, what is to be done?
Regards,
thelink123
Printable View
Hi,
Kindly see the snippet below
In this p is constant and not the value pointed to by p;Code:
typedef int *ptr;
const ptr p;
Suppose if we want to make the value pointed to by p, a constant, what is to be done?
Regards,
thelink123
I believe your only choice is to change the typedef or create a new typedef or not use it:
Code:typedef const int *ptr;
ptr p;
Thanks cwr :)
It is best not to use pointers with typedefs because they generally cause confusion. Typedef the actual type, but not the pointer part of the type.
Like
typedef int myint;
const myint* p;