Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,884 questions

51,810 answers

573 users

How to use constants in Go

3 Answers

0 votes
package main
 
import (
  "fmt"
  "math"
)

const s string = "golang"
 
func main() {
    fmt.Println(s)
	
	const x = 8392
	const v = 93478353 / x
    fmt.Println(v)
	
	fmt.Println(math.Cos(x))
}
 
 
 
/*
     
run:
 
golang
11138
-0.692373995461725
 
*/

 



answered Feb 21, 2020 by avibootz
0 votes
package main
 
import "fmt"
 
const Pi = 3.14159
 
func main() {
    const s = "go"
    fmt.Println(s)
     
    // s = "abc" // Error: cannot assign to s
     
    fmt.Println(Pi);
 
    const b = true
    fmt.Println(b)
     
    // const t := "temp" // syntax error: unexpected :=, expecting =
}
 
 
 
/*
run:
 
go
3.14159
true
 
*/

 



answered May 4, 2024 by avibootz
0 votes
package main
 
import "fmt"
 
const (
    a = 23875345
    b = -8
)
 
 
func main() {
    fmt.Println(a)
    fmt.Println(b)
}
 
 
 
/*
run:
 
23875345
-8
 
*/

 



answered May 4, 2024 by avibootz

Related questions

1 answer 208 views
1 answer 67 views
67 views asked Jul 11, 2025 by avibootz
1 answer 55 views
1 answer 60 views
2 answers 78 views
2 answers 103 views
103 views asked May 6, 2025 by avibootz
...