当前位置:网站首页>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
边栏推荐
- Introduction to intrusion detection data set
- Elastic box model
- GSI-ECM工程建设管理数字化平台
- Leetcode 542, 01 matrix
- Leetcode 1346. Check whether integers and their multiples exist
- Unity animation creates sequence frame code and generates animationclip
- [SQL] string series 2: split a string into multiple lines according to specific characters
- Go限制深度遍历目录下文件
- 高薪程序员&面试题精讲系列91之Limit 20000加载很慢怎么解决?如何定位慢SQL?
- pikachuxss如何获取cookie靶场,返回首页总是失败
猜你喜欢
【SQL】字符串系列2:将一个字符串根据特定字符分拆成多行
Shanghai responded that "flour official website is an illegal website": neglect of operation and maintenance has been "hacked", and the police have filed a case
Leetcode 542, 01 matrix
41. 缺失的第一个正数
高薪程序员&面试题精讲系列91之Limit 20000加载很慢怎么解决?如何定位慢SQL?
Rt-1052 learning notes - GPIO architecture analysis
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
一些接地气的话儿
Matlab analytic hierarchy process to quickly calculate the weight
上海回應“面粉官網是非法網站”:疏於運維被“黑”,警方已立案
随机推荐
How do BIM swindlers cheat? (turn)
LeetCode 116. Populate the next right node pointer for each node
居家第二十三天的午饭
bounding box iou
Leetcode 20. Valid parentheses
Unity solves Z-fighting
中创存储|想要一个好用的分布式存储云盘,到底该怎么选
Async function ------ ES6
【PTA】L1-006 连续因子
Cmake project under vs2019: calculating binocular parallax using elas method
How to use PM2 management application? Come in and see
Three. Based on ply format point cloud voxel model JS upload interface writing
Common form verification
Actual measurement of automatic ticket grabbing script of barley network based on selenium (the first part of the new year)
三十.什么是vm和vc?
Parsing methods of JSON data in C - jar and jobobject: error reading jar from jsonreader Current JsonReader item
ABAQUS script email auto notification
Scrapy教程 - (2)寫一個簡單爬蟲
Shanghai responded that "flour official website is an illegal website": neglect of operation and maintenance has been "hacked", and the police have filed a case
堡垒机、跳板机JumpServer的搭建,以及使用,图文详细