Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.Indirect() Function in Golang is used to get the value that v points to, i.e., If v is a nil pointer, Indirect returns a zero Value. If v is not a pointer, Indirect returns v. To access this function, one needs to imports the reflect package in the program.
Syntax:func Indirect(v Value) Value
Parameters: This function takes the following parameters:
- v: This parameter is the value to be passed.
Return Value: This function returns the value that v points to.
Below examples illustrate the use of the above method in Golang:
&val2 type : ptr indirectI type : slice indirectI value : [1 2 3 4]
val1: slice val2 type : array &val3 type : ptr val3 type : map
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.