Intermediate Go (Golang)
Q88 / 100

What is the difference between new(T) and &T{}?

Correct! Well done.

Incorrect.

The correct answer is B) new(T) allocates zeroed memory for any type; &T{} is struct literal syntax allowing field initialization and is idiomatic for structs

B

Correct Answer

new(T) allocates zeroed memory for any type; &T{} is struct literal syntax allowing field initialization and is idiomatic for structs

Explanation

For structs, &Point{X: 1, Y: 2} is idiomatic and allows initialization. new(Point) gives a zeroed *Point. For non-struct types (maps, slices), use make instead.

Progress
88/100