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

Leave a comment

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