Opérateurs
Contexte
Section intitulée « Contexte »Go propose des opérateurs similaires au C, avec quelques spécificités.
Catégories
Section intitulée « Catégories »- Arithmétiques :
+-*/% - Comparaison :
==!=<<=>>= - Logiques :
&&||! - Bit à bit :
&|^&^(ET NON)<<>> - Assignation :
=+=-=*=/=%=&=|=^=<<=>>=
Utilisation de différents opérateurs.
Code exemple
Section intitulée « Code exemple »package main
import "fmt"
func main() { a, b := 10, 3 fmt.Println("Addition :", a+b) fmt.Println("Division entière :", a/b) fmt.Println("Reste :", a%b)
// Opérateurs logiques x, y := true, false fmt.Println("x && y :", x && y) fmt.Println("x || y :", x || y)
// Bit à bit c, d := 0b1100, 0b1010 fmt.Printf("c & d = %b\n", c&d) // 1000 fmt.Printf("c | d = %b\n", c|d) // 1110 fmt.Printf("c ^ d = %b\n", c^d) // 0110 fmt.Printf("c &^ d = %b\n", c&^d) // 0100 fmt.Printf("c << 1 = %b\n", c<<1) // 11000}Addition : 13Division entière : 3Reste : 1x && y : falsex || y : truec & d = 1000c | d = 1110c ^ d = 110c &^ d = 100c << 1 = 11000