当前位置:网站首页>Go language shallow copy and deep copy
Go language shallow copy and deep copy
2022-06-26 07:59:00 【mq-shao】
- Deep copy : Copy the data , Two variables have different addresses , After copying, the operation of the two variables does not affect each other
- Shallow copy : Copy address , After the copy, the operation of the two variables affects each other , Modification of one variable will affect another variable
package main
import (
"fmt"
)
func main() {
var src []int
src = []int{1, 2, 3}
fmt.Println(" Initial value src : ", src)
fmt.Println("---------------------")
des1 := src
des2 := make([]int, len(src))
copy(des2, src)
fmt.Println(" Shallow copy des1: ", des1)
fmt.Println(" Deep copy des2: ", des2)
fmt.Println("---------------------")
src[1] = 0
fmt.Println(" modify src : ", src)
fmt.Println("des1: ", des1)
fmt.Println("des2: ", des2)
}
边栏推荐
- Deeply analyze storage costs and find cost reduction solutions
- Go语言浅拷贝与深拷贝
- C#/. Net phase VI 01C Foundation_ 02:vs2019 basic operations, excluding code files, smart tips, data types, differences between float and double, and differences between string and string
- [UVM practice] Chapter 3: UVM Fundamentals (3) field automation mechanism
- Okhttp3 source code explanation (IV) cache strategy, disadvantages of Android mixed development
- 手机开户哪个证券公司佣金最低?网上开户是否安全么?
- Use intent to shuttle between activities -- use implicit intent
- Junit
- Win11 open folder Caton solution summary
- Flower instruction WP
猜你喜欢

Wifi-802.11 2.4G band 5g band channel frequency allocation table

Detailed explanation of the generate go file command of import in golang (absolute detail)

buuresevewp

Junit

Nine hours, nine people and nine doors (01 backpack deformation) - Niuke

Uniapp uses uviewui

WiFi-802.11 2.4G频段 5G频段 信道频率分配表

Uniapp wechat withdrawal (packaged as app)

ASP. Net and Net framework and C #

Children play games (greed, prefix and) - Niuke winter vacation training camp
随机推荐
Informatics Orsay all in one 1354: bracket matching test
Attention mechanism yyds, AI editor finally bid farewell to P and destroyed the whole picture
Chapter II (summary)
Power apps application practice | easily develop employee leave attendance management applet with power apps
Tsinghua Yaoban chendanqi won Sloan award! He is a classmate with last year's winner Ma Tengyu. His doctoral thesis is one of the hottest in the past decade
Minor problems in importing D
JWT in go
I want to open a stock account at a discount. How do I do it? Is it safe to open a mobile account?
Children play games (greed, prefix and) - Niuke winter vacation training camp
Important reference indicators for data center disaster recovery: RTO and RPO
Use middleware to record slow laravel requests
Google Earth engine (GEE) 02 basic knowledge and learning resources
Common uniapp configurations
Jemter stress test - basic requirements - [teaching]
What is Wi Fi 6 (802.11ax)? Why is Wi Fi 6 important?
buuresevewp
Listview control
Redis (4) -- Talking about integer set
You can command Siri without making a sound! The Chinese team of Cornell University developed the silent language recognition necklace. Chinese and English are OK
Jz-063- median in data stream