当前位置:网站首页>go defer
go defer
2022-04-23 20:43:00 【baboon_ chen】
One 、defer principle
Two 、 Example
1、
package main
import (
"fmt"
)
func funcA() int {
x := 5
defer func() {
x += 1
}()
return x
}
func main() {
fmt.Println(funcA())
}
/* Output :5 reason : The return value in defer It was determined before */
2、
func funcB() (x int) {
defer func() {
x += 1
}()
return 5
}
/* Output :6 reason : First the 5 Assign a value to x, defer Call again x */
3、
func funcC() (y int) {
x := 5
defer func() {
x += 1
}()
return x
}
/* Output :5 reason : First the 5 Assign a value to y, defer Only change x */
4、
func funcD() (x int) {
defer func(x int) {
x += 1
}(x)
return 5
}
/* Output :5 reason : First the 5 Assign a value to x, defer Call again x( Value passed ), What has changed is x Copy of */
版权声明
本文为[baboon_ chen]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210546351196.html
边栏推荐
- Some basic knowledge of devexpress report development
- Bash script learning -- for loop traversal
- BMP JPEG picture to vector image contourtrace
- LeetCode 116. Populate the next right node pointer for each node
- CONDA environment management command
- 6-5 字符串 - 2. 字符串复制(赋值) (10 分)C语言标准函数库中包括 strcpy 函数,用于字符串复制(赋值)。作为练习,我们自己编写一个功能与之相同的函数。
- Shanghai a répondu que « le site officiel de la farine est illégal »: l'exploitation et l'entretien négligents ont été « noirs » et la police a déposé une plainte
- Unity Odin ProgressBar add value column
- Commande dos pour la pénétration de l'Intranet
- Go zero framework database avoidance Guide
猜你喜欢
[SQL] string series 2: split a string into multiple lines according to specific characters
Install MySQL 5.0 under Linux 64bit 6 - the root password cannot be modified
On BIM data redundancy theory
Solution: NPM err! code ELIFECYCLE npm ERR! errno 1
【栈和队列专题】—— 滑动窗口
Shanghai a répondu que « le site officiel de la farine est illégal »: l'exploitation et l'entretien négligents ont été « noirs » et la police a déposé une plainte
MySQL基础之写表(创建表)
Cmake project under vs2019: calculating binocular parallax using elas method
go slice
Elastic box model
随机推荐
Matlab analytic hierarchy process to quickly calculate the weight
Matlab matrix index problem
The ODB model calculates the data and outputs it to excel
MySQL基础合集
3-5通过XSS获取cookie以及XSS后台管理系统的使用
[SQL] string series 2: split a string into multiple lines according to specific characters
浅谈数据库设计之三大范式
UnhandledPromiseRejectionwarning:CastError: Cast to ObjectId failed for value
2021-09-02 unity project uses rider to build hot change project failure record of ilruntime
Three. Based on ply format point cloud voxel model JS upload interface writing
Mathematical modeling column | Part 5: MATLAB optimization model solving method (Part I): Standard Model
启牛学堂有用吗,推荐的证券账户是否安全
Plato farm is one of the four largest online IEOS in metauniverse, and the transaction on the chain is quite high
bounding box iou
Leetcode 20. Valid parentheses
A useless confession artifact
An error occurs when the addressable assets system project is packaged. Runtimedata is null
中创存储|想要一个好用的分布式存储云盘,到底该怎么选
RT-1052学习笔记 - GPIO架构分析
Syntax Error: TypeError: this. getOptions is not a function