Skip to content
Related Articles

Related Articles

reflect.Complex() Function in Golang with Examples
  • Last Updated : 03 May, 2020

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.Complex() Function in Golang is used to get the v’s underlying value. To access this function, one needs to imports the reflect package in the program.

Syntax:

func (v Value) Complex() complex128

Parameters: This function does not accept any parameters.

Return Value: This function returns the v’s underlying value.

Below examples illustrate the use of the above method in Golang:



Example 1:




// Golang program to illustrate 
// reflect.complex() Function 
  
package main
   
 import (
    "fmt"
    "reflect"
 )
  
 func main() {        
    fmt.Println(reflect.ValueOf(complex(0, 0)).Complex())
  
 }                 

Output:

(0+0i)

Example 2:




// Golang program to illustrate 
// reflect.Complex() Function 
  
package main
   
 import (
    "fmt"
    "reflect"
 )
   
const a = complex(100, 8)
  
 const b = complex(8, 100)
  
 func main() {
    fmt.Println("Complex number a : ", a)
    fmt.Println("Complex number b : ", b)
      
    c := a + b
          
    fmt.Println(reflect.ValueOf(c).Complex())
  
 }         

Output:

Complex number a :  (100+8i)
Complex number b :  (8+100i)
(108+108i)

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.

My Personal Notes arrow_drop_up
Recommended Articles
Page :