What is the use of the 'new' keyword in Go?
- Allocates memory for a new variable
- Copies the value of a variable
- Deallocates memory for a variable
- Initializes a variable with zero value
The 'new' keyword in Go is used to allocate memory for a new variable. It initializes the variable with the zero value of its type and returns a pointer to the newly allocated memory. This is particularly useful when working with composite types like structs where the 'make' keyword isn't applicable.
Loading...
Related Quiz
- Explain how you would read from a file in Go line by line.
- What are the advantages of using Protocol Buffers over JSON for data serialization?
- Interfaces in Go are satisfied _____.
- You are tasked with improving the performance of a Go application. How would you use unit testing to identify and verify optimizations?
- The _______ option in Gorm is used to specify additional conditions in database queries.