In the Go programming language; how can pointers to pointers become useful?
(Why are they not illegal if they are not really useful?)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The usefulness of any data type depends on the problem being solved and on the method used to solve the problem. If a data type does not fit the problem, it simply does not fit the problem – and there is nothing more to it.
The Go programming language (as well as most other programming languages) is based on simple rules that the programmer can use to build new data types. Some of these rules are:
*T: create a new data type that is a pointer to T[10]T: an array of Tsstruct { t T; u U ... }: a structure which contains a T as a componentThe programmer can create complex data types by composing these simple rules. The total number of possible data types exceeds the number of useful data types. Clearly, there exist (and have to exist) data types which aren’t useful at all. This is just a natural consequence of the fact that the rules for building new data types are simple.
The type
**Tfalls into the category of types which are less probable to appear in a program. The fact that it is possible to write*****Tdoesn’t imply that such a type has to be immensely useful.And finally, the answer to your question:
The type
**Tusually appears in contexts where we want to redirect users of a value of typeTto another value of typeT, but for some reason we do not have access to all users of the value or finding the users would cost too much time:T(for some reason)Tto access the value via a pointerTto another valueIn such a situation, using
**Tis natural because it allows us to implement the 3rd step in O(1):