go main

2026-08-30 浏览 (1)

main.go 源码

// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
// For more tutorials  : https://learngoprogramming.com
// In-person training  : https://www.linkedin.com/in/inancgumus/
// Follow me on twitter: https://twitter.com/inancgumus

// ---------------------------------------------------------
// EXERCISE: Basics
//
//  Let's warm up with the pointer basics. Please follow the
//  instructions inside the code. Run the solution to see
//  its output if you need to.
// ---------------------------------------------------------

package main

type computer struct {
	brand string
}

func main() {
	// create a nil pointer with the type of pointer to a computer

	// compare the pointer variable to a nil value, and say it's nil

	// create an apple computer by putting its address to a pointer variable

	// put the apple into a new pointer variable

	// compare the apples: if they are equal say so and print their addresses

	// create a sony computer by putting its address to a new pointer variable

	// compare apple to sony, if they are not equal say so and print their
	// addresses

	// put apple's value into a new ordinary variable

	// print apple pointer variable's address, and the address it points to
	// and, print the new variable's addresses as well

	// compare the value that is pointed by the apple and the new variable
	// if they are equal say so

	// print the values:
	// the value that is pointed by the apple and the new variable

	// create a new function: change
	// the func can change the given computer's brand to another brand

	// change sony's brand to hp using the func — print sony's brand

	// write a func that returns the value that is pointed by the given *computer
	// print the returned value

	// write a new constructor func that returns a pointer to a computer
	// and call the func 3 times and print the returned values' addresses
}

你可能感兴趣的文章

go main

go main

go main

go main

go main

go Header

go main

go main

go main

go main

  • 所属分类: 后端技术
  • 本文标签: golang
  • 版权声明: 本文链接 https://seaxiang.com/blog/5AGWCI2k