当前位置:网站首页>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)
}
边栏推荐
- [UVM basics] TLM common data receiving and sending and data receiving examples
- [issue 22] sheen cloud platform one side & two sides
- 项目管理学习
- buuresevewp
- 解决 psycopg2.NotSupportedError: PQconninfo not available in libpq < 9.3
- Es performance tuning and other features
- Handwritten instanceof underlying principle
- [UVM practice] Chapter 2: a simple UVM verification platform (4) the ultimate masterpiece of UVM: sequence
- Yyds dry inventory executor package (executor function)
- 信息学奥赛一本通 1354:括弧匹配检验
猜你喜欢

I want to create SQL data (storage structure)

Niuniu looks at the cloud (greedy, hash, push formula) - the first session of Niuke winter vacation training camp

Multi interface switching in one UI of QT

Take you three minutes to get started typescript

Chapter 3 (data types and expressions)

arduino——ATtiny85 SSD1306 + DHT

Baoyan postgraduate entrance examination interview - operating system

Attention mechanism yyds, AI editor finally bid farewell to P and destroyed the whole picture

Solve psycopg2 NotSupportedError: PQconninfo not available in libpq < 9.3

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
随机推荐
Bluebridge cup 1 introduction training Fibonacci series
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
Use intent to shuttle between activities -- use implicit intent
Jemter stress test - visualization tool - [usage]
Es performance tuning and other features
Leetcode topic [array] -11- containers with the most rainwater
Exploration and practice of incremental data Lake in station B
Apache InLong毕业成为顶级项目,具备百万亿级数据流处理能力!
arduino——ATtiny85 SSD1306 + DHT
Hand drawn style chart library chart Implementation principle of xkcd
Which securities company has the lowest Commission for opening a mobile account? Is it safe to open an account online?
Google Earth engine (GEE) 01- the prompt shortcut ctrl+space cannot be used
Interview for postgraduate entrance examination of Baoyan University - machine learning
[UVM basics] connect of UVM_ Phase execution sequence
Pic 10B parsing
Chapter 5 (array)
Arrangement and insertion structure
Household enterprises use WMS warehouse management system. What are the changes
Baoyan postgraduate entrance examination interview - Network
JWT in go