Skip to content

Instantly share code, notes, and snippets.

@sembug
Last active March 31, 2025 23:53
Show Gist options
  • Select an option

  • Save sembug/04b9404ed6bf2efda6382c2d4f0f71ff to your computer and use it in GitHub Desktop.

Select an option

Save sembug/04b9404ed6bf2efda6382c2d4f0f71ff to your computer and use it in GitHub Desktop.
Go Notes
type car struct {
  brand string
  model string
}

type truck struct {
  car
  bedSize int
}

lanesTruck := truck{
  bedSize: 10,
  car: car{
    brand: "Toyota",
    model: "Camry",
  },
}

fmt.Println(lanesTruck.brand) // Toyota
fmt.Println(lanesTruck.model) // Camry
package main

func createMatrix(rows, cols int) [][]int {
	matrix := make([][]int, 0)
	for _ = range rows {
		matrix = append(matrix, make([]int, cols))
	}
	for i := range matrix {
		for j := range matrix[i] {
			matrix[i][j] = i * j
		}
	}
	return matrix
}

package main

func createMatrix(rows, cols int) [][]int {
	matrix := make([][]int, rows)
	for i := 0; i < rows; i++ {
		matrix[i] = make([]int, cols)
		for j := 0; j < cols; j++ {
			matrix[i][j] = i * j
		}
	}
	return matrix
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment