Brother Lian Blockchain technology training to share the implementation of the Go language defer

Source: Internet
Author: User

Internet more than 20 years, has reached the crossroads. Before the advent of the blockchain, the internet was known as the classical Internet, and the use of blockchain technology in the Internet only entered the post-Internet era. As a new technology, the blockchain is undoubtedly on the cusp, and its development prospects for the general public will eventually be positive. But at present, because the blockchain technology is in the early stage of development, there are some problems, such as technology maturity and limited application scenario, the Brother Education advises users to carefully consider and discern before choosing professional Go Language + blockchain training institution.

Execution of defer in Golang

Everyone knows Golang's defer keyword, which can perform some operations before the function is returned, most commonly used to open a resource (such as a file, database connection, etc.) and use defer delay to turn off the resource to avoid a memory leak. For example:

Func do () (ok bool) {

File,_: = os. Open ("C:\a.txt")

Defer file. Close ()

DoSomething

return OK

}

We can see in the official document that the order of execution of defer is in reverse order, that is, the advanced sequence:


For I: = 0; I < 5; i++ {

Defer FMT. Printf ("%d", i)

}

The print result is: 4,3,2,1,0


Then look at this example:


Func Deferret (x, y int) (z int) {

Defer z + = 100

z = x + y

Return z + 50//execution Order z = z+50 (call defer) Z = z+100, ret

}


Func Main () {

I: = Deferret (+)

println (i)//print 152

}

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

Follow brother Lian Blockchain technology public number get more technical dry Goods Oh!!!

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.