Skip to content

Latest commit

 

History

History
31 lines (21 loc) · 1.24 KB

File metadata and controls

31 lines (21 loc) · 1.24 KB

Exercise 2.1 - Basics

If you do not finish during the lecture period, please finish it as homework.

Pointers (swap.go)

  • Write a function to swap two integer variables in the caller function (2 ways)
  • Write a function to swap two integer pointers in the caller function (2 ways)
  • Write test example code "ExampleSwap inside a swap_test file

Questions

What is the difference between a pointer and a Java object reference? What happens if you assign nil to a pointer variable and dereference the pointer?

Book Index (Working with maps, arrays and slices)

A Book Index is a inverted index which lists all pages a word occurs in a book. Write a program which generates an inverted index out of an array of book pages. Each Page contains an array of words.

  • Define custom types for Book, Page and Index
  • Make sure the Stringer() interface is implemented for Book and Index to make them printable
  • Write an unit test which generates a book and calculates the index and prints it to Stdout

After this Exercise

  • You know difference between Pointers and Values
  • You know the basic Go container types: string, map, array, slice
  • You know how to make custom types printable
  • You know how to write basic unit tests