Go language Knowledge points notes

Source: Internet
Author: User
This is a created article in which the information may have evolved or changed.

Curly braces for Golang:

In go, the curly brackets that inherit the C-series are indicated as a scope block, but different from the curly brace position in C/D + +, go requires that "{" must be on the right side (one line of code), not a separate line.

Variables for Golang:

In go, unused variables or packages can cause compilation errors, which is a mandatory behavior that cannot be changed to warnings, making code debugging a little cumbersome.

It is particularly important to note that in go, if you return the address (pointer) of a local variable inside a function, the variable is stored in the heap by the compiler, not in the stack, so returning a local variable is a legitimate behavior.

Golang Array and slice:

In go, array length can be self-inferred, slice slice can also be self-inferred, the difference between the two syntax is there is no ellipsis (...)

A: = [...] Int{1, 2, 3}    //arrays: = [   ]int{1, 2, 3}    //slice

Golang expression:

In Go, i++ is a statement rather than an expression, so j = i++, FMT. A statement such as Printf ("%d", i++) is wrong. In addition, go does not have a predecessor + +, that is, there is no ++i this statement.

Golang Charter System:

The package keyword is used to define a bundle. The filename of the source file does not need to match the package name. The package name uses lowercase letters, and lowercase is convention rather than mandatory. A package of go can consist of one or more files (unlike Java a package is a file), files that belong to the same package use the same "package name " to name a package. Although you do not use the package name to determine the file name, use the package name to determine the directory name of the source file, that is, the package name must be the same as the package's source file's parent directory.

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.