constants/

directory
v0.0.0-...-86d22a7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2017 License: Apache-2.0

README

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.

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.

Directories

Path Synopsis
Sample program to show how to declare constants and their implementation in Go.
Sample program to show how to declare constants and their implementation in Go.
Sample program to show how constants do have a parallel type system.
Sample program to show how constants do have a parallel type system.
Sample program to show how iota works.
Sample program to show how iota works.
Sample program to show how literal, constant and variables work within the scope of implicit conversion.
Sample program to show how literal, constant and variables work within the scope of implicit conversion.
exercises
exercise1
Declare an untyped and typed constant and display their values.
Declare an untyped and typed constant and display their values.
template1
Declare an untyped and typed constant and display their values.
Declare an untyped and typed constant and display their values.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL