###makeとnewの違い
違いはポインタを返すかどうか
make → ポインタを返さない
new → ポインタを返す
main.go
package main
import(
"fmt"
)
func main(){
var p *int = new(int)
fmt.Printf("%T\n", p) => *int
s := make([]int, 0)
fmt.Printf("%T\n", s) => []int
}
Go to list of users who liked
More than 3 years have passed since last update.
###makeとnewの違い
違いはポインタを返すかどうか
make → ポインタを返さない
new → ポインタを返す
package main
import(
"fmt"
)
func main(){
var p *int = new(int)
fmt.Printf("%T\n", p) => *int
s := make([]int, 0)
fmt.Printf("%T\n", s) => []int
}
Register as a new user and use Qiita more conveniently
Go to list of users who liked