In a performance-critical section of your code, you need to efficiently swap the values of two variables. Which operator could you use to achieve this in Go?
- a ^= b ^= a ^= b
- a, b = b, a
- swap(a, b)
- temp := a; a = b; b = temp
Go supports multiple assignment, enabling swapping of variables using a, b = b, a. This approach is concise and efficient, ideal for performance-critical sections.
Loading...
Related Quiz
- Explain how Go's garbage collector works. What are some key characteristics?
- You're writing unit tests for a function that should return an error under certain conditions. How would you test this behavior in Go?
- By default, the HTTP server in Go listens on port _______.
- The go-torch tool is used for _____ profiling of Go applications.
- The _________ package in Go allows you to load Go packages dynamically.