Skip to content

Instantly share code, notes, and snippets.

@marti1125
Last active August 21, 2019 02:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marti1125/4c74919ffa69939672557bce4406eef7 to your computer and use it in GitHub Desktop.
Save marti1125/4c74919ffa69939672557bce4406eef7 to your computer and use it in GitHub Desktop.
[golang] examples
package main
import (
"math"
"fmt"
)
func main() {
maxInt8 := math.MaxInt8
minInt8 := math.MinInt8
maxInt16 := math.MaxInt16
minInt16 := math.MinInt16
maxInt32 := math.MaxInt32
minInt32 := math.MinInt32
var maxInt64 int64
maxInt64 = math.MaxInt64
var minInt64 int64
minInt64 = math.MinInt64
maxUint8 := math.MaxUint8
maxUint16 := math.MaxUint16
var maxUint32 uint32
maxUint32 = math.MaxUint32
var maxUint64 uint64
maxUint64 = math.MaxUint64
maxFloat32 := math.MaxFloat32
maxFloat64 := math.MaxFloat64
fmt.Println("Range of Int8 :: ", minInt8, " to ", maxInt8)
fmt.Println("Range of Int16 :: ", minInt16, " to ", maxInt16)
fmt.Println("Range of Int32 :: ", minInt32, " to ", maxInt32)
fmt.Println("Range of Int64 :: ", minInt64, " to ", maxInt64)
fmt.Println("Max Uint8 :: ", maxUint8)
fmt.Println("Max Uint16 :: ", maxUint16)
fmt.Println("Max Uint32 :: ", maxUint32)
fmt.Println("Max Uint64 :: ", maxUint64)
fmt.Println("Max Float32 :: ", maxFloat32)
fmt.Println("Max Float64 :: ", maxFloat64)
s := "hello, World!"
r := []rune(s)
r[0] = 'H'
s2 := string(r)
fmt.Println(s2)
/*numbers := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
sum := 0
for i := 0; i < len(numbers); i++ {
sum += numbers[i]
}
fmt.Println("Sum is :: ", sum)*/
numbers := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
sum := 0
i := 0
n := len(numbers)
for {
sum += numbers[i]
i++
if i >= n {
break
}
}
fmt.Println("Sum is :: ", sum)
numbers := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
sum := 0
for index, val := range numbers {
sum += val
fmt.Print("[", index, ",", val, "] ")
}
fmt.Println("\nSum is :: ", sum)
kvs := map[int]string{1: "apple", 2: "banana"}
for k, v := range kvs {
fmt.Println(k, " -> ", v)
}
str := "Hello, World!"
for index, c := range str {
fmt.Println("[", index, ",", string(c), "] ")
}
data := 10
ptr := &data
fmt.Println("Value stored at variable var is ", data)
fmt.Println("Value stored at variable var is ", *ptr)
fmt.Println("The address of variable var is ", &data)
fmt.Println("The address of variable var is ", ptr)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment