Go Operators

Gayathri. B

Go Operators

  • In Go, operators are used to carry out operations on variables and values.
  • For example, the + operator adds two numbers together, as shown below:

Example:

package main
import "fmt"
func main() {
  var sum = 15 + 25
  fmt.Println(sum)
}

Output:

40
This program adds 15 and 25, and prints the result 40.

Go Operators Example:

  • Operators are used in Go to perform various operations on variables and values.

Example:

package main
import ("fmt")
func main() {
  var (
    sum1 = 100 + 50       // 150: Addition of 100 and 50
    sum2 = sum1 + 250     // 400: Addition of sum1 and 250
    sum3 = sum2 + sum2    // 800: Doubling sum2
  )
  fmt.Println(sum3)
}

Types of Operators in Go:

Go categorizes operators into the following groups:


  • Arithmetic Operators
  • Assignment Operators
  • Comparison Operators
  • Logical Operators
  • Bitwise Operators
Each group serves a specific purpose and is used depending on the type of operation needed.



Tags
Our website uses cookies to enhance your experience. Learn More
Accept !

GocourseAI

close
send