go questions

2026-08-30 浏览 (1)

Which one is a correct type conversion expression?

  • convert(40)
  • var("hi")
  • int(4.) CORRECT
  • int[4]

What does this code print?

age := 6.5
fmt.Print(int(age))
  • 6.5
  • 65
  • 6 CORRECT
  • .5

When you convert a float to integer It loses its fractional part

What does this code print?

fmt.Print(int(6.5))
  • 6.5
  • 65
  • 6
  • Compile-Time Error CORRECT

Go can detect conversion errors at the compile-time

What does this code print?

area := 10.5
fmt.Print(area/2)
  • 5.25 CORRECT
  • 5
  • 0
  • Error

What does this code print?

area := 10.5
div := 2
fmt.Print(area/div)
  • 5.25
  • 5
  • ERROR CORRECT

You can't divide different type of values. You need to convert: area / float64(div)

Which code below can fix the following code?

area := 10.5
div := 2
fmt.Print(area/div)
  • fmt.Print(int(area)/div) // 5
  • fmt.Print(area/int(div)) // type mismatch
  • fmt.Print(int(area)/int(div)) // 5
  • fmt.Print(area/float64(div)) CORRECT

你可能感兴趣的文章

go main

go main

go main

go main

go main

go Header

go main

go main

go main

go main

  • 所属分类: 后端技术
  • 本文标签: golang
  • 版权声明: 本文链接 https://seaxiang.com/blog/gr3FwglR