|
-
September 25th, 2006, 03:56 PM
#1
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
-
September 25th, 2006, 04:36 PM
#2
Re: Double **pointer question!
arg2 = new type *[]
pointer is an invaluable asset to efficient, robust software architecture without sacrificing resources
Kuphryn
Last edited by kuphryn; September 25th, 2006 at 04:39 PM.
-
September 25th, 2006, 04:41 PM
#3
Re: Double **pointer question!
 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;
}
-
September 26th, 2006, 01:06 AM
#4
Re: Double **pointer question!
-
September 26th, 2006, 01:25 AM
#5
Re: Double **pointer question!
here is a Small mistake in the Following Code
 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
Last edited by humptydumpty; September 26th, 2006 at 02:00 AM.
-
September 26th, 2006, 01:33 AM
#6
Re: Double **pointer question!
 Originally Posted by HD
here is a Small mistake in the Following Code
I didn't catch the mistake you are talking about...
-
September 26th, 2006, 01:57 AM
#7
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
-
September 26th, 2006, 02:01 AM
#8
Re: Double **pointer question!
A, ok. Sorry, didn't pay attention to the comments.
-
September 26th, 2006, 02:05 AM
#9
Re: Double **pointer question!
it's okay Cilu. Even that was a Minute mistake .
Thanx
-
September 26th, 2006, 02:25 AM
#10
Re: Double **pointer question!
 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.
C++ program ran... C++ program crashed... C++ programmer quit !!   
Regards
Shaq
-
September 26th, 2006, 02:33 AM
#11
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
-
September 26th, 2006, 06:47 AM
#12
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|