Pointer pointer to pointer

Duplicate:

Used for multiple levels of pointer markup

I have a question about C and pointers.

I know when I will need a pointer, and even when I might need a pointer to a pointer. For example, if I had a linked list and I wanted to write a function that would remove an item from that list, for that I would need to send a pointer to the head pointer of the list.

How about pointer to pointer to pointer? Will there ever be a situation when it is needed? Extra points if you have some sample code for me to circle around.

0


a source to share


4 answers


Vector is *, array is **, volume is ***, temporary space is ****.



+2


a source


Extremely rare, but you can imagine some sort of reference counting scenario where you needed to go to some other address of the pointers object and change it.



0


a source


How about a function to remove an item from a linked list in an array of linked lists, or a function to remove an item from a linked list in an array of arrays of links ... you get my point.

0


a source


Pointers are arrays in a sense. Here's a simple scenario. Let's say you've built a text editor. Rows and columns are dynamic.

You can have an "array" of strings, and since they are dynamic, it will be a pointer. Then your columns will be dynamic as well and can be contained within your line array. So essentially:

char **lines;

      

You will need to line up your line first before adding symbols, but this can provide very rough editor tools.

lines = malloc(num_of_lines_in_my_file);
lines[0] = malloc(num_of_chars_for_line_1);

      

Certainly not pretty code, but hopefully it helps a little to answer the question.

0


a source







All Articles