Home > Backend Development > Golang > When and Why Use Pointers to Pointers (int)?

When and Why Use Pointers to Pointers (int)?

Barbara Streisand
Release: 2024-11-16 12:48:03
Original
1058 people have browsed it

When and Why Use Pointers to Pointers (int)?

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template