Vee's Golang Notes

Lab Two

21 Sep 2025

Intrinsic Data Types (Go Version)

  1. Given the following enumeration concept, write a Go program to output the values associated with each constant.
    Use an iota-based const block.
const (
    RED = iota
    YELLOW
    AMBER = YELLOW
    GREEN
)

  1. Write a program in which you define variables of the following kinds
  • integer
  • pointer to integer
  • another variable that refers to the same integer (simulate a reference)
  • constant integer

Perform the following actions on the variables

  • assign the value 5 to the integer
  • increment the integer through the pointer
  • increment the integer through the reference variable
  • output the integer and verify that its value is 7

What happens if you attempt to change the value of the constant?

Output the decimal values of the following literals:

  • 0xf3f2
  • 0437
  • 'a'

  1. Write a program which reads a single line of hyphen-connected words and outputs the words one per line, with a count of the number of characters in each.

Example:

Enter words: hello-this-is-a-line-of-input
[5] hello
[4] this
[2] is
[1] a
[4] line
[2] of
[5] input

Use only primitive byte/character slices and pointer-style indexing (no strings.Split or other helpers).


  1. Using the Go string type, create a type definition for an array of 10 strings.
    Using the type, create an array and then read 10 string objects from standard input, and output the string with the largest size.

  1. Repeat the previous exercise using a type alias.
    Which syntax do you find more readable?

Optional Question

  1. Write a 2-dimensional noughts and crosses (tic-tac-toe) game implemented with either a 1D or 2D array.
    The game should display the board using an X character for a cross, O for a nought, and ? for a free location.

The program should first display an empty board (full of ?s) and repeatedly prompt two users for their next move.
Requests for Xs and Os are made alternately.
Moves may be indicated by a two-digit code (0 0 for top-left, 2 2 for bottom-right) or any other helpful mechanism.

Example:

?  ?  ?    
?  ?  ?
?  ?  ?

X move: 1 1
?  ?  ?        
?  X  ?
?  ?  ?

O move:

This exercise will be extended in later chapters.