-
Notifications
You must be signed in to change notification settings - Fork 0
/
operators.go
80 lines (67 loc) · 1.4 KB
/
operators.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import "fmt"
func main() {
/*
* All types of operators in golang are like so:
*
* 1. Arithmetic Operators
* 2. Assignment Operators
* 3. Comparison Operators
* 4. Logical Operators
* 5. Bitwise Operators
*/
// Arithmetic Operators Examples
var (
a int8 = 1 + 1 // Addition
b int8 = 5 - 1 // Substraction
c int8 = 2 * 3 // Multiplication
d int8 = 10 / 2 // Division
e int8 = 10 % 2 // Modulus
)
c++ // Increment
c-- // Decrement
// Assignment Operators
a += b // Add and assign
a -= b // Subtract and assign
a *= b // Multiply and assign
a /= b // Divide and assign quotient
a %= b // Divide and assign modulus
// Comparison Operators
var (
f = a == b // Equal
g = a != b // Not equal
h = a < b // Less than
i = a <= b // Less than or equal to
j = a > b // Greater than
k = a >= b // Greater than or equal to
)
// Logical Operators
var l = a < b && d > e
var m = a < b || d > e
// Bitwise Operators
var (
n = a & b // AND
o = a | b // OR
p = a ^ b // XOR
q = a << b // Zero fill left shift
r = a >> b // Signed right shift
)
fmt.Println(a)
fmt.Println(b)
fmt.Println(c)
fmt.Println(d)
fmt.Println(e)
fmt.Println(f)
fmt.Println(g)
fmt.Println(h)
fmt.Println(i)
fmt.Println(j)
fmt.Println(k)
fmt.Println(l)
fmt.Println(m)
fmt.Println(n)
fmt.Println(o)
fmt.Println(p)
fmt.Println(q)
fmt.Println(r)
}