Skip to content

Commit 06eba1c

Browse files
committed
const
1 parent 6c65f2a commit 06eba1c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

4_constants/constants.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package main
2+
3+
import "fmt"
4+
//before function it can be declared
5+
//but := short hand cant be used outside function
6+
const age=30
7+
const word="go" //-whenever needed can be used in the program
8+
9+
func main(){
10+
const name string = "golang" //type can skippked it infers itself
11+
12+
//try to reassign the value its not allowed
13+
//-name="js" ---not allowed
14+
15+
/*int*/
16+
//const age=30
17+
fmt.Println(age)
18+
19+
20+
//--CONSTANT GROUPING--// (Whenever u need many constants)
21+
const (
22+
port=5000
23+
host="localhost"
24+
)
25+
fmt.Println(port,host)
26+
27+
}

0 commit comments

Comments
 (0)