Section4.26
This commit is contained in:
50
Section4/constants/main.go
Normal file
50
Section4/constants/main.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func main() {
|
||||
const days int = 7
|
||||
|
||||
var i int
|
||||
fmt.Println(i)
|
||||
|
||||
const pi float64 = 3.14
|
||||
const secondsInHours = 3600
|
||||
|
||||
duration := 234 //hours
|
||||
fmt.Printf("Duration in seconds: %v\n", duration*secondsInHours)
|
||||
|
||||
x, y := 5, 1
|
||||
fmt.Println(x / y)
|
||||
|
||||
const a = 5
|
||||
const b = 1
|
||||
fmt.Println(a / b)
|
||||
|
||||
const n, m int = 4, 5
|
||||
const n1, m1 = 6, 7
|
||||
|
||||
const (
|
||||
min1 = -500
|
||||
min2
|
||||
min3
|
||||
)
|
||||
fmt.Println(min1, min2, min3)
|
||||
|
||||
//Constant rules
|
||||
//1. you can not change a constant
|
||||
const temp int = 100
|
||||
//temp = 50
|
||||
|
||||
//2. You can not initiate a constant at run time
|
||||
// const power = math.Pow(2, 3)
|
||||
|
||||
//3. You can not use a variable to initiate a constant
|
||||
//t := 5
|
||||
//const tc = t
|
||||
|
||||
//4.
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user