What practical use can a pointer on pointer have?
Page 1 of 1
madmax17




Posts: 19563
Location: Croatia
PostPosted: Mon, 17th Jan 2011 00:12    Post subject: What practical use can a pointer on pointer have?
In c language.
Back to top
tainted4ever
VIP Member



Posts: 11336

PostPosted: Mon, 17th Jan 2011 02:12    Post subject:
Data structure full of pointers has a pointer coming to it? That's all I can think of off the top of my head.


Sense Amid Madness, Wit Amidst Folly
Back to top
Werelds
Special Little Man



Posts: 15098
Location: 0100111001001100
PostPosted: Mon, 17th Jan 2011 09:57    Post subject:
Well here's a (terrible) example:

void foo(char ** bar) {
*bar = malloc(255);
strcpy(*bar, "Hello World");
}

int main() {
char *bar = 0;
foo(&bar); // bar contains "Hello World" after this
free(bar);
return 0;
}

And indeed, it might get used for lists to pointers and such. An easy example is for example your arguments coming into main(); can be "char * argv[]" or "char ** argv" Smile
Back to top
garus
VIP Member



Posts: 34197

PostPosted: Mon, 17th Jan 2011 10:10    Post subject:
snip


Last edited by garus on Tue, 27th Aug 2024 21:40; edited 1 time in total
Back to top
[mrt]
[Admin] Code Monkey



Posts: 1342

PostPosted: Wed, 19th Jan 2011 20:59    Post subject:
Simply, it allows you to change (modify) the pointer that is passed to you. It's usually used when a function allocates some memory within itself and then it passes it back to you, instead of you allocating a buffer and passing it to the function.

pwerelds function does that Smile


teey
Back to top
Page 1 of 1 All times are GMT + 1 Hour
NFOHump.com Forum Index - Programmers Corner
Signature/Avatar nuking: none (can be changed in your profile)  


Display posts from previous:   

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2.0.8 © 2001, 2002 phpBB Group