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.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *