当前位置:网站首页>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
边栏推荐
- Fastdfs思维导图
- MySQL数据库常识之储存引擎
- 2022dasctf APR x fat epidemic prevention challenge crypto easy_ real
- Async function ------ ES6
- Devexpress 14.1 installation record
- Commande dos pour la pénétration de l'Intranet
- Summary and effect analysis of methods for calculating binocular parallax
- How to use PM2 management application? Come in and see
- Automatically fill in body temperature and win10 task plan
- Awk print special characters
猜你喜欢
居家第二十三天的午饭
Commande dos pour la pénétration de l'Intranet
缓存淘汰算法初步认识(LRU和LFU)
[stack and queue topics] - sliding window
高薪程序员&面试题精讲系列91之Limit 20000加载很慢怎么解决?如何定位慢SQL?
【PTA】整除光棍
Elastic box model
Cmake project under vs2019: calculating binocular parallax using elas method
Unity solves Z-fighting
GO语言开发天天生鲜项目第三天 案例-新闻发布系统二
随机推荐
[PTA] get rid of singles
Experience of mathematical modeling in 18 year research competition
Matlab analytic hierarchy process to quickly calculate the weight
LeetCode 232、用栈实现队列
Async function ------ ES6
Preliminary understanding of cache elimination algorithm (LRU and LFU)
ABAQUS script email auto notification
On IRP from the perspective of source code
Leetcode 542, 01 matrix
SQL: query duplicate data and delete duplicate data
The ODB model calculates the data and outputs it to excel
SQL gets the latest record of the data table
2021-09-02 unity project uses rider to build hot change project failure record of ilruntime
Leetcode 709, convert to lowercase
XXXI` Prototype ` displays prototype properties and`__ proto__` Implicit prototype properties
JS arrow function user and processing method of converting arrow function into ordinary function
Imitation Baidu map realizes the three buttons to switch the map mode by automatically shrinking the bottom
RT-1052学习笔记 - GPIO架构分析
Go限制深度遍历目录下文件
MySQL stored procedures and functions