Skip to content

Latest commit

 

History

History
38 lines (26 loc) · 1.65 KB

README.md

File metadata and controls

38 lines (26 loc) · 1.65 KB

Constants

Constants are a way to create a named identifier whose value can never change. They also provide an incredible amount of flexibility to the language. The way constants are implemented in Go is very unique.

Notes

  • Constants are not variables.
  • They exist only at compilation.
  • Untyped constants can be implictly converted where typed constants and variables can't.
  • Think of untyped constants as having a Kind, not a Type.
  • Learn about explicit and implicit conversions.
  • See the power of constants and their use in the standard library.

Links

https://golang.org/ref/spec#Constants
http://blog.golang.org/constants
http://www.goinggo.net/2014/04/introduction-to-numeric-constants-in-go.html

Code Review

Declare and initialize constants (Go Playground)
Parallel type system (Kind) (Go Playground)
iota (Go Playground)
Implicit conversion (Go Playground)

Exercises

Exercise 1

Part A: Declare an untyped and typed constant and display their values.

Part B: Divide two literal constants into a typed variable and display the value.

Template (Go Playground) | Answer (Go Playground)


All material is licensed under the Apache License Version 2.0, January 2004.