pointer to the pointer??!!! I am not familiar with this idea. Can you elaborate a bit further?
Is it something like this:
I declared a pointer of type int. So compiler will temporarily allocate an address for this pointer until I initialize it or what.....I am getting no further....
&myVar is the "address of" a variable so you can store it in a pointer;
int* myIntPointer = &myIntVar; // set pointer to be "address of" var.
*myPointer is the value that is pointed to rather than the pointer itself.
myIntVar = *myIntPointer; // sets int to be what the pointer is pointing at.
Not sure if this is part of the misunderstanding or if you are just being imprecise. The type of a pointer can't be int because an int is not a pointer. The type of the pointer is actually pointer to int (int*).
AMDA10 wrote:
pointer to the pointer??!!! I am not familiar with this idea. Can you elaborate a bit further?
Pointer types are not as special as you might think. You can copy, pass them to functions and point to them using pointers the same way as with other types.
To get a pointer to a type you put an asterisk after the type name.
int* is a pointer to an int.
int** is a pointer to an int*.
int*** is a pointer to an int**.
...
pointer to the pointer??!!! I am not familiar with this idea. Can you elaborate a bit further?
A pointer is just a variable, like any other. The value it holds is interpreted as a memory address. If you can have a pointer to an int, or a pointer to a char, then you can also have a pointer to a pointer.
You can use it for all the reasons you'd use a pointer to any other type - e.g. for manipulating a C-style array of pointers, or for C-style passing a pointer by reference.
In C++, there's much less use for them - but then, in C++, there's much less use for pointers in general.
"*someIntPointer" means a value stored at the location to which "someIntPointer" pointer is pointing.
"someIntPointer" means the value stored at the address of the pointer "*someIntPointer"
"&someIntPointer" means the address where "*someIntPointer" pointer itself is located. Note that this is different than that of the address of variable the pointer points to.
"**someIntPointer": here someIntPointer is pointing to another pointer, lets say "secondPointer". Secondpointer points to a variable int type "secondVar". So "**someIntPointer" means the value at secondVar.
The value of **someIntPointer is: someIntPointer [the value is a hex number which is address of "secondpointer"]
and its address is: &someIntPointer
/* Possible ways to find value of variable num*/
printf("\n Value of num is: %d", num); // output ## Value of num is: 123
printf("\n Value of num using pr2 is: %d", *pr2); // output ## Value of num using pr2 is: 123
printf("\n Value of num using pr1 is: %d", **pr1); // output ## Value of num using pr1 is: 123
/*Possible ways to find address of num*/
printf("\n Address of num is: %u", &num); // output ## Address of num is: XX771230
printf("\n Address of num using pr2 is: %u", pr2); // output ## Address of num using pr2 is: XX771230
printf("\n Address of num using pr1 is: %u", *pr1); // output ## Address of num using pr1 is: XX771230
/*Find value of pointer*/
printf("\n Value of Pointer pr2 is: %u", pr2); // output ## Value of Pointer pr2 is: XX771230
printf("\n Value of Pointer pr2 using pr1 is: %u", *pr1); // output ## Value of Pointer pr2 using pr1 is: XX771230
/*Ways to find address of pointer*/
printf("\n Address of Pointer pr2 is:%u",&pr2); // output ## Address of Pointer pr2 is: 66X123X1
printf("\n Address of Pointer pr2 using pr1 is:%u",*pr1); // output ## Address of Pointer pr2 using pr1 is: 66X123X1
/*Double pointer value and address*/
printf("\n Value of Pointer pr1 is:%u",pr1); // output ## Value of Pointer pr1 is: 66X123X1
printf("\n Address of Pointer pr1 is:%u",&pr1); // output ## Address of Pointer pr1 is: XX661111
pr1 pr2 num
value: 66X123X1 XX771230 123
address: XX661111 66X123X1 XX771230
"someIntPointer" means the value stored at the address of the pointer "*someIntPointer"
Huh? That makes no sense. *someIntPointer isn't a pointer - it is, as you yourself said on your previous line, the value stored at the location that someIntPointer points to.