Pointee of Pointers: Pointers to Pointers
Pointers to pointers, commonly denoted as **int, may not immediately seem like a practical concept. However, they can provide valuable utility in certain use cases:
Function Parameters
In function parameters, it can be advantageous to employ pointers to pointers. Imagine a function that modifies the target of a variable rather than the variable's contents. For instance, a function that reassigns the pointer of a struct can be implemented using **Node, where Node is a pointer to a pointer to the struct.
HTML Manipulation
In web development, pointers to pointers can streamline the handling of HTML pages. Functions that operate on HTML pages may require parsing the page if it has not been parsed previously. By employing **html.Node, these functions can preserve the parsed tree for future use, avoiding the need for repeated parsing.
Additional Return Values
In certain languages that lack multiple return values, pointers to pointers can serve as a means of returning an additional value. For example, Objective-C methods commonly employ NSError* as a parameter to optionally return an NSError object.
These are but a few scenarios where pointers to pointers can prove useful. Despite their less intuitive nature, they can enhance code readability and maintainability in specific circumstances.
The above is the detailed content of When and Why Use Pointers to Pointers (int)?. For more information, please follow other related articles on the PHP Chinese website!