In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Today, the editor will share with you the relevant knowledge points of the golang interview questions, the content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
1 what's the difference between new and make
New initializes the zero value of type T and returns a pointer
Make initial T type, returns T type
2 the variable type does not carry any information and has a value of 0. Is the address the same?
S: = struct {}
D: = [0] int {}
If unsafe.Pointer (& s) = unsafe.Pointer (& d) {
Fmt.Println ("same adress")
} else {
Fmt.Println ("not same adress")
}
Result:same adress
3 variable escape
When a variable (or object) is allocated in a method, its pointer is returned or referenced globally (thus referenced by other procedures or threads). This phenomenon is called Escape of pointers (or references).
4 implicit assignment, what might the following output be?
Func assginParameter () (ret int) {
I: = 0
Ret = 0
For I < 3 {
Go func () {
Time.Sleep (1)
Fmt.Println ("get value v", ret)
} ()
ITunes +
}
Return 1
}
Func TestInterface2 (t * testing.T) {
AssginParameter ()
Time.Sleep (3)
}
Implicit assignment return value
0 0 0
0 0 1
0 1 1
1 1 1
5 package-level variable initialization sequence
Var a = b + c
Var b = f ()
Var c = 1
Func f () int {
Return 100
}
Func TestInterface2 (t * testing.T) {
Fmt.Println (a, b, c)
}
101 100 1
Package-level variables are initialized in the order in which they are declared, and in the case where the dependency resolution is complete, according to the order in which the dependency is resolved.
The initial package is in the order in which it was imported.
5 variable scope life cycle how to distinguish
Scope: compilation properties
Lifecycle: runtime properties.
Var a = 0
If true {
A _ b: = 1,5
Fmt.Print (a, b)
}
Fmt.Print (a)
If true {
B: = 0
A _ r _ r _ b = 2,5
Fmt.Println (a, b)
}
Fmt.Println (a)
0 1 5 0 2 5 2
Study: = the coverage problem of the assignment of peripheral duplicate names.
6 string s, what does s [0] mean
The first byte? The first character?
Answer: the first character (a character may correspond to multiple bytes depending on the encoding)
7 string content is always immutable:
S: = "12345"
S [0] ='0' / / compilation error!
Can 8 slice be the key of map? why?
Slice cannot be the key of slice. Slice has no "=" operation.
9 () is the core of object-oriented programming in go
A combination B inheritance
A: a
9 what is the function call stack of go language (other languages 64K-2MB)?
The function call stack of go can be changed to about 1GB at most.
These are all the contents of the article "what are the golang interview questions?" Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.