Variables Cheatsheet

Program Structure

package main // Entry point package

import "fmt" // Standard library import

func main() {
    // Execution starts here
}

Variable Declaration

// Standard (Inside or Outside functions)
var x int = 10

// Short (Inside functions ONLY)
y := 20

// Multiple variables
a, b := 1, "hello"

Zero Values

  • int: 0
  • float64: 0.0
  • string: ""
  • bool: false

Basic Types

Type Description Example
int Whole numbers var i int = 42
float64 Decimals f := 3.14
string Text s := "Go"
bool True/False b := true
byte 8-bit data var d byte = 0xFF

Key Concepts

  • Static Typing: Types are checked at compile time.
  • Strong Typing: No automatic type conversion (must use int(val)).
  • Compiled: Code is converted to a standalone machine binary.
  • Go Runtime: Handles Garbage Collection (GC) automatically.
  • Comments: // single and /* multi */.