|
From: Shachar R. <sha...@gm...> - 2005-08-12 10:36:39
|
On 8/12/05, Farzan Hajian <far...@ho...> wrote:
> Hi,
> I have a problem with variable declaration.
> Please tell me what the following declaration means?
>=20
> int * const * ptr;
>=20
> I know that "ptr" is a pointer to "int * const". But what "int * const"
> means.
You have a 2 level pointer, out of which the second one is constant. I
will try to illustrate this:
Lets assume ptr =3D=3D 0x1000
Additionally, in address 0x1000 you have the value 0x2000
And finally, in address 0x2000 you have the value 0x3000
So, writing **ptr will get you the integer value at address 0x2000
(meaning if you will do printf("0x%X",**ptr); you will get 0x3000) ,
and will allow you to change it (meaning that you will be able to
assign a different value there), and writing *ptr will get you the
address 0x2000 (meaning that if you will do printf("%p",*ptr); you
will get 0x2000), which you won't be able to change. Finally, you will
be able to change address ptr itself is pointing to, which currently
is 0x1000.
Regards,
Shachar
|