Will I ever use "Pointer of type pointer to int?" Or any other type like double, char or whatever? And if so, when and where?
Thanks,
Dat
Will I ever use "Pointer of type pointer to int?" Or any other type like double, char or whatever? And if so, when and where?
Thanks,
Dat
Dat
http://hoteden.com <-- not an porn site damnit!
when you need it, be ready to use it. but they are not the most common pointers. i've used char **foo a bunch with text parsing stuff.
hello, internet!
It is sometimes useful in linked lists. If you want to modify the previous node's NextNode pointer from the current node, you need to get the adress of that pointer to change it from within the previous node (Did that make sense? Well, I tried... ).
Code://Not good, only the local pointer is changed void SetNextNode(NODE* Node) { Node = this->NextNode; } //Works better void SetNextNode(NODE** Node) { *Node = this->NextNode; }
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Huh?Originally posted by Magos
It is sometimes useful in linked lists. If you want to modify the previous node's NextNode pointer from the current node, you need to get the adress of that pointer to change it from within the previous node (Did that make sense? Well, I tried... ).
Code://Not good, only the local pointer is changed void SetNextNode(NODE* Node) { Node = this->NextNode; } //Works better void SetNextNode(NODE** Node) { *Node = this->NextNode; }
Dat
http://hoteden.com <-- not an porn site damnit!
You'll obviously need a pointer if you want to pass a pointer by reference as in Magos' example.
Here's the same thing, but you might grasp it better :
If the parameter fp was just a FILE*, then the stream would only be accessible within the function OpenFile(), and not outside it.Code:int OpenFile(FILE** fp, char* fileName, char* mode) { if ( (*fp = fopen(fileName, mode)) == NULL ) { return -1; } return 0; }
it's part of a linked list.Huh?
Study linked lists, very cool and usefull
I agree.Study linked lists, very cool and usefull
Currently i am studying linked list, there are two different implementations-- array-based and use malloc()'s linked list(sorry dunno the name). My question is:
When i use the array-based linked list, i usually define a constant first like #define MAX_NODE 999. u know, the constant is fixed so if the data exceeds the MAX_NODE, the linked list can't handle the data. The conclusion is: array-based linked list is not so good. Am i right?
Depends. Everything has its good and bad sides. Having a static array as the list consumes unused memory if you have little data, and might not be large enough if you have a lot of data.Originally posted by FCF
The conclusion is: array-based linked list is not so good. Am i right?
On the other hand, you can't directly access a specific element using a dynamic linked list, though you can theoretically store an unfinite amount of data.
If you know exactly how many elements you need to store, use arrays. If you don't know (you might add or delete during run-time) use a dynamic linked list.