variables/

directory
v0.0.0-...-818bd76 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: Apache-2.0

README

Variables

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

  • The purpose of all programs and all parts of those programs is to transform data from one form to the other.
  • Code primarily allocates, reads and writes to memory.
  • Understanding type is crucial to writing good code and understanding code.
  • If you don't understand the data, you don't understand the problem.
  • You understand the problem better by understanding the data.
  • 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.

Built-In Types
Variables
Gustavo's IEEE-754 Brain Teaser - William Kennedy
What's in a name
A brief history of “type” - Arcane Sentiment

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)


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