Go Operators

Go Language - Operators

A symbol which helps the compiler to perform specific logical or mathematical calculations are called operators. Go language has several types of operators as it is rich in built-in operators.

  • Arithmetic Operators
  • Relational Operators
  • Bitwise Operators
  • Logical Operators
  • Miscellaneous Operators
  • Assignment operators

Arithmetic Operators :

go-language-arithmatic-operators

Example :

CODE/PROGRAM/EXAMPLE
import "fmt"	/* Program to explain Arithmetic Operators */
func main() {
	var a int = 2
	var b int = 1
	var c int
	c = a + b
	fmt.Printf("Value of c is %d\n", c )
	c = a - b
	fmt.Printf("Value of c is %d\n", c )
	c = a * b
	fmt.Printf("Value of c is %d\n", c )
	c = a / b
	fmt.Printf("Value of c is %d\n", c )
	c = a % b
	fmt.Printf("Value of c is %d\n", c )
	a++
	fmt.Printf("Value of a is %d\n", a )
	a--
	fmt.Printf("Value of a is %d\n", a )
	}
	
Output :
Value of c is 3
Value of c is 0
Value of c is 2
Value of c is 2
Value of c is 0
Value of a is 3
Value of a is 2

Logical operators :

go-language-logical-operator

Example :

CODE/PROGRAM/EXAMPLE
package main
import "fmt"
func main() {
	var a bool = true
	var b bool = false
	if ( a || b ) {		//Logical OR
		fmt.Printf("Logical OR-Condition is true when either a or b is true\n" )
		}
		if ( !( b) ) {	//Logical NOT
		fmt.Printf("Logical NOT-Condition is true when b is false\n" )
		}
		b = true		/*changing the value for b*/
		if ( a && b ) {			//Logical AND
		fmt.Printf("Logical AND-Condition is true when both and b are true\n" )
		}
		}
		
Output:
Logical OR-Condition is true when either a or b is true
Logical NOT-Condition is true when b is false
Logical AND-Condition is true when both and b are true
#golang_operators #golang_bitwise_operators #golang_logical_operators #golang_mod_operator #golang_increment_operator #conditional_operator_in_golang #golang_atomic_increment #go_assignment_operator #operator_overloading_golang #Miscellaneous_Operators

(New page will open, for Comment)

Not yet commented...