Double **pointer question!
Question regarding Double pointers.
It was told to me that if you passed a double pointer as an argument to a function :
int function1(type arg1, (type**) &arg2)
{
....
}
That you are passing the address to the pointer which, which is assumed is pointing to something else. And, that by doing so, you allow the function to point that double pointer to something else.
My question is, if it is a temporary storage of the address to the pointer that the function is receiving dictated no more than by (type**), how would you re-assign it to another address. Would you have to declare a new pointer in the function and assign it the (type**) address to it, then point it to something else?
And my last question (part II) is where does pointers really come into play and are helpful/useful?
Thanks much
Re: Double **pointer question!
arg2 = new type *[]
pointer is an invaluable asset to efficient, robust software architecture without sacrificing resources
Kuphryn
Re: Double **pointer question!
Quote:
Originally Posted by pghTech
That you are passing the address to the pointer which, which is assumed is pointing to something else. And, that by doing so, you allow the function to point that double pointer to something else.
Code:
int i = 5;
int j = 6;
int* pi = &i;
void func(int** ppi)
{
// make pi point to j
*ppi = &j;
// change j to 10
**ppi = 10;
// chenge ppi. this only affects the local copy ppi
ppi = 100;
}
int main()
{
//pass double pointer (address of pi)
func(&pi);
return 0;
}
Re: Double **pointer question!
Re: Double **pointer question!
here is a Small mistake in the Following Code
Quote:
Originally Posted by wildfrog
Code:
int i = 5;
int j = 6;
int* pi = &i;
void func(int** ppi)
{
// make pi point to j
*ppi = &j;
// change j to 10
**ppi = 10;
// chenge ppi. this only affects the local copy ppi
ppi = 100;//And this Line contain Error too you are trying to convert const int to int**
}
int main()
{
//pass double pointer (address of pi)
func(&pi);
return 0;
}
Am i right Peter.
Code:
void func(int** ppi)
{
// make pi point to i
int my =25;
int *my1 =&my;
*ppi = &j; //assign 15 to ppi
*ppi =&i;//change value to ppi
ppi =&my1;//affect only upto local copy
cout<<**ppi;//will print 25 here
cout<<"\n";
}
int main()
{
//pass double pointer (address of pi)
int *pi;
func(&pi);
cout<<*pi;//here it will print 10
return 0;
}
Thanx
Re: Double **pointer question!
Quote:
Originally Posted by HD
here is a Small mistake in the Following Code
I didn't catch the mistake you are talking about...
Re: Double **pointer question!
mention in bold letter
and here is The line.
Code:
ppi = 100;//And this Line contain Error too you are trying to convert const int to int**
Thanx
Re: Double **pointer question!
A, ok. Sorry, didn't pay attention to the comments. ;)
Re: Double **pointer question!
it's okay Cilu. Even that was a Minute mistake .
Thanx
Re: Double **pointer question!
Quote:
Originally Posted by pghTech
And my last question (part II) is where does pointers really come into play and are helpful/useful?
One....
Heart & soul of COM.... interfaces.
To obtain interface address from the component.
Re: Double **pointer question!
That is.But i think when you want to perform calculation on Address of your data.that time you use pointers.
Thanx
Re: Double **pointer question!
Thanks everyone for your reply's.
I made a mistake in my original post.
Instead of asking how "pointers" are helpful, I meant to ask
"How are DOUBLE pointers helpful", since they are already setup to be helpful in the sense that you can point to something else, or in the case of an array of pointers, easily change the sort easily.