GO OPERATORS

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.

1.Arithmetic Operators:

Arithmetic Operators are used to perform mathematical operations on numeric values such as addition, subtraction, multiplication, division, etc. These are some of the basic operators in programming and mathematics.

2.Assignment Operators:

Assignment operators are used in programming to assign values to variables. The most basic assignment operator is =, which simply assigns the value on the right-hand side to the variable on the left-hand side.

3.Comparison Operators:

Comparison operators are used to compare two values. The result of a comparison operation is always a Boolean value: either true or false.
These operators are essential in decision-making processes like in if, while, and for statements.

4.Logical Operators :

Logical operators are used to combine two or more conditions (also called expressions) and return a Boolean result: true or false. These operators are primarily used in decision-making, conditional statements, and loops in programming.

5.Bitwise Operators:

Bitwise operators are used to perform operations on individual bits of integer values. These operators work directly at the binary level, meaning they manipulate data one bit at a time.




More topic in Go

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