当前位置:网站首页>func(){}() 一种奇怪的写法,不知道属于什么范畴
func(){}() 一种奇怪的写法,不知道属于什么范畴
2022-07-15 19:03:00 【李海成】
func defer_exe_time() (i int) {
i = 9
defer func() {
//defer后可以跟一个func
fmt.Printf("first i=%d\n", i) //打印5,而非9。充分理解“defer在函数返回前执行”的含义,不是在“return语句前执行defer”
}()
defer func(i int) {
fmt.Printf("second i=%d\n", i) //打印9
}(i)
defer fmt.Printf("third i=%d\n", i) //defer后不是跟func,而直接跟一条执行语句,则相关变量在注册defer时被拷贝或计算
return 5
}
上述代码中有一种奇怪的写法,func(){}(),不知道是否属于defer特有,第一个()表示形参,{}表示方法体,第二个()表示实参。这就表示对该函数进行了调用。
边栏推荐
- SSH 学习杂记
- Analyzing the starting point of modern maker Education
- MySQL中KEY、PRIMARY KEY、UNIQUE KEY、INDEX 的区别
- 【微服务】Nacos数据持久化以及集群的搭建
- When the wechat applet activates the account, it will prompt "this account has been activated, please log in directly with the account password"
- Interpreting the teaching principles of robot programming course
- What is the execution method of polardb for PostgreSQL's HTAP cross machine parallel query?
- (codeforce631) c.report (monotone stack)
- MySQL about the installation process of zip installation package
- 简约不简单的编程语言go
猜你喜欢

金融、生物医药、集成电路,上海巨头行业用AI加持核心竞争力

EasyCVR视频调阅页面如何增加对应视频的云台控制?

简约不简单的编程语言go

HMS core graphics and image technology shows the latest functions and application scenarios, and accelerates the construction of digital intelligence life

Basic learning about MySQL

【MATLAB项目实战】基于GUI的数字信号处理系统

(2021牛客多校三)J-Counting Triangles(思维)

少儿编程中项目式学习的创造性

MySQL 版本升级心得

解析现代化创客教育的出发点
随机推荐
[leetcode weekly -- string] 6114 Move the clip to get the string
上海的这一新数字规划,为 NFT、元宇宙等带来了新的可能性
(2021牛客多校五)B-Boxes(概率期望)
Without training code, the reasoning performance is improved by 1.4 ~ 7.1 times, and the industry's first automatic model compression tool is open source!
[in depth study of 4g/5g/6g special topic -37]: urllc-8 - in depth interpretation of 3GPP urllc related protocols, specifications and technical principles -2- network architecture, delay analysis and
Rendering and cloud rendering: 25% of the production time of a movie is "waiting"
Edusoho enterprise training version does not connect to the cloud and starts double speed playback
Allure测试报告怎么设置
HMS Core图形图像技术展现最新功能和应用场景,加速构建数智生活
[Halcon] WriteImage保存图像崩溃问题
国产版Postman工具,好用!
STM32 and Internet of things 02 network data sending and receiving
SQL也能做AI ?没错!MLOps Meetup V3 回顾|OpenMLBD+SQLFlow+Byzer
洛谷P4052 [JSOI2007]文本生成器 题解
使用buildroot学习驱动开发
Insight into the puzzle of database, 2022 Jincang innovative product launch was held
无需训练代码,推理性能提升1.4~7.1倍,业界首个自动模型压缩工具开源
同花顺开户安全吗,同属顺是证券公司吗?
Honghu Wanlian Zhiyuan development board is officially integrated into the openharmony backbone
iNFTnews | NFT門票將改變參與活動的方式