Concept Flow - Constants
Declare constant with const keyword
Assign fixed value
Use constant in code
Value cannot change
Program runs
Constants are fixed values set once and used throughout the program without change.
package main import "fmt" const Pi = 3.14 func main() { fmt.Println(Pi) }
| Step | Action | Evaluation | Result |
|---|---|---|---|
| 1 | Declare constant Pi | const Pi = 3.14 | Pi is set to 3.14 |
| 2 | Enter main function | func main() | Ready to execute main |
| 3 | Print Pi | fmt.Println(Pi) | Outputs 3.14 |
| 4 | End program | No further code | Program terminates |
| Variable | Start | After 1 | After 2 | Final |
|---|---|---|---|---|
| Pi | undefined | 3.14 | 3.14 | 3.14 |
Constants in Go: - Declared with 'const' keyword - Assigned a fixed value at declaration - Value cannot be changed later - Used like variables but immutable - Helps prevent accidental value changes