跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[程序员] Go 语言存在隐式类型转换?

发表于

忘了在哪本书上看到的例子:

package main

import "fmt"

func main() {
	// 不指定类型时为浮点数
	var a = 2e3
	fmt.Printf("%T: %v\n", a, a) // 输出:float64: 2000

	// 编译成功,因为 1.5e3 等于 1500 ,是一个整数
	var b int = 1.5e3
	fmt.Printf("%T: %v\n", b, b) // 输出:int: 1500
}

上面代码中,为什么 var b int = 1.5e3 能通过编译,难道科学计数法被视为算术表达式或常量表达式?不然我只能认为 Go 语言存在隐式类型转换了。

有请知道的大佬解答原因,还有没有类似的情况呢?

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.