Brother Lian Blockchain training share go language-make and new

Source: Internet
Author: User

Blockchain is a complex and complex discipline that combines cryptography, consensus algorithms, intelligent contracts, and super-ledgers. Yun Jong said that the quality of the teachers in the blockchain training institutions and their perceived level in the blockchain industry were uneven, and the average consumer was not.

The go language is primarily used as a server-side development, targeting the development of "large software", suitable for many programmers to develop large-scale software together, and the development cycle of long-term support for cloud computing network services. The go language enables programmers to develop quickly, and it makes it easier for programmers to maintain and modify the software as it grows. It combines the efficiency of a traditional compiled language with the ease of use and expression of a scripting language.

There are two memory allocation mechanisms in Golang: New and make, which differ significantly from each other.

New:new (t) allocates a 0 value to the memory space of the type T, and returns its address, which is the value of a *t type. itself is a pointer. Can be used to initialize any type


Make: Returns a T type with an initial value (not 0), instead of *t, which can only be used to initialize: Slice,map and channel three types.

Contrast:

Scope of application: Make can only create built-in types (slice map channel), and new is memory-allocated for all types

Return value: New Returns a pointer, make returns a reference

Padding value: New fills 0 values, make fills non 0 values

Code:

Package Main


Import (

"FMT"

"Reflect"

)


Type Books struct {

Title,

Content,

Author string

}


Func Main () {


A: = new ([]int)

Fmt. Println (a)

The output &[],a itself is an address

B: = make ([]int, 1)

Fmt. Println (b)

The output [0],b itself is a slice object whose content defaults to 0


Book1: = new (Books)

Book1. title = "This is Book1 title"

Book1. Content = "This is Book1 content"

Book1. Author = "This is Book1 Author"

BOOK2: = books{"This was Book2 title", "This is the Book2 content", "This is Book2 author"}

Fmt. Println ("Book1:", Book1, ", Type:", reflect. TypeOf (Book1))

Book1: &{this is Book1 title This is Book1 content this is Book1 author}, Type: *main. Books

Fmt. Println ("Book2:", Book2, ", Type:", reflect. TypeOf (BOOK2))

Book2: {This was Book2 title this is BOOK2 content of this is Book2 author}, Type:main. Books

}

high-energy early warning, brother even education blockchain live course August continues to hit the hot!

The original price of 1188 Yuan of 12 block chain advanced courses, now only need 1 Yuan!

Also can receive free "Go Language foundation actual combat project development" and "Go language Advanced Combat Project development" textbook Two!!

Limited time limit!! First come first served!!

Http://www.ydma.cn/open/course/24


Pay attention to Brother chain public number can get more Blockchain technology dry!!!


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.