01-variables/

directory
v0.0.0-...-35bbffe Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2015 License: Apache-2.0

README

Variables - Language Syntax

Variables are at the heart of the language and provide the ability to read from and write to memory. In Go, access to memory is type safe. This means the compiler takes type seriously and will not allow us to use variables outside the scope of how they are declared.

Notes

  • When variables are being declared to their zero value, use the keyword var.
  • When variables are being declared and initialized, use the short variable declaration operator.
  • Escape analysis is used to determine when a value escapes to the heap.

Built-In Types

https://golang.org/doc/effective_go.html#variables

http://www.goinggo.net/2013/08/gustavos-ieee-754-brain-teaser.html

Code Review

Declare and initialize variables (Go Playground)

Exercises

Exercise 1

Part A: Declare three variables that are initialized to their zero value and three declared with a literal value. Declare variables of type string, int and bool. Display the values of those variables.

Part B: Declare a new variable of type float32 and initialize the variable by converting the literal value of Pi (3.14).

Template (Go Playground) | Answer (Go Playground)


Ardan Labs Ardan Studios GoingGo Blog


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

Directories

Path Synopsis
Sample program to show how to declare variables.
Sample program to show how to declare variables.
exercises
exercise1
Declare three variables that are initialized to their zero value and three declared with a literal value.
Declare three variables that are initialized to their zero value and three declared with a literal value.
template1
Declare three variables that are initialized to their zero value and three declared with a literal value.
Declare three variables that are initialized to their zero value and three declared with a literal value.

Jump to

Keyboard shortcuts

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