variable
  • A. p.name
  • B. (&p).name
  • C. (*p).name
  • D. p->name
Answer
AC
variable1
package main

import (
	"fmt"
)

func main() {
	var ans float64 = 15 + 25 + 5.2
	fmt.Println(ans)
}
  • A. 45
  • B. 45.0
  • C. 45.2
  • D. compliation error
Answer
Try it
C
variable2
package main

import (
	"fmt"
)

func main() {
	var ans float64 = 3 / 2
	fmt.Println(ans)
}
  • A. 1.5
  • B. 1
  • C. 0
  • D. compliation error
Answer
Try it
B
variable3
package main

func main() {
	const a int8 = -1
	var b int8 = -128 / a

	println(b)
}
Answer
Try it
compliation error
-128 / a (constant 128 of type int8) overflows int8
variable4
package main

func main() {
	var a int8 = -1
	var b int8 = -128 / a

	println(b)
}
Answer
Try it
-128
variable5
package main

import "fmt"

type MyInt1 int
type MyInt2 = int

func main() {
	var i int =0
	var i1 MyInt1 = i
	var i2 MyInt2 = i
	fmt.Println(i1, i2)
}
Answer
Try it
compilation error
cannot use i (variable of type int) as MyInt1 value in variable declaration
variable6
package main

import "fmt"

func main() {
	const X = 7.0
	var x interface{} = X
	if y, ok := x.(int); ok {
		fmt.Println(y)
	} else {
		fmt.Println(int(y))
	}
}
  • A. 7
  • B. 7.0
  • C. 0
  • D. compilation error
Answer
Try it
C