struct_types/

directory
v0.0.0-...-dca8f84 Latest Latest
Warning

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

Go to latest
Published: May 27, 2016 License: Apache-2.0

README

Struct Types

Struct types are a way of creating complex types that group fields of data together. They are a great way of organizing and sharing the different aspects of the data your program consumes.

A computer architecture’s potential performance is determined predominantly by its word length (the number of bits that can be processed per access) and, more importantly, memory size, or the number of words that it can access.

Notes

  • We can use the struct literal form to initialize a value from a struct type.
  • The dot (.) operator allows us to access individual field values.
  • We can create anonymous structs.

http://www.goinggo.net/2013/07/understanding-type-in-go.html
http://www.goinggo.net/2013/07/object-oriented-programming-in-go.html
http://dave.cheney.net/2015/10/09/padding-is-hard
http://www.geeksforgeeks.org/structure-member-alignment-padding-and-data-packing
http://www.catb.org/esr/structure-packing

Code Review

Declare, create and initialize struct types (Go Playground)
Anonymous struct types (Go Playground)
Named vs Unnamed types (Go Playground)

Advanced Code Review

Struct type alignments (Go Playground)

Exercises

Exercise 1

Part A: Declare a struct type to maintain information about a user (name, email and age). Create a value of this type, initialize with values and display each field.

Part B: Declare and initialize an anonymous struct type with the same three fields. Display the value.

Template (Go Playground) | Answer (Go Playground)


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

Directories

Path Synopsis
advanced
example1
Sample program to show how struct types align on boundaries.
Sample program to show how struct types align on boundaries.
Sample program to show how to declare and initialize struct types.
Sample program to show how to declare and initialize struct types.
Sample program to show how to declare and initialize anonymous struct types.
Sample program to show how to declare and initialize anonymous struct types.
Sample program to show how variables of an unnamed type can be assigned to variables of a named type, when they are identical.
Sample program to show how variables of an unnamed type can be assigned to variables of a named type, when they are identical.
exercises
exercise1
Declare a struct type to maintain information about a user (name, email and age).
Declare a struct type to maintain information about a user (name, email and age).
template1
Declare a struct type to maintain information about a user (name, email and age).
Declare a struct type to maintain information about a user (name, email and age).

Jump to

Keyboard shortcuts

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