The basic grammar and built-in data types of Go language _golang

Source: Internet
Author: User

Go token
The Go program includes a variety of tokens and tokens that can be a keyword, an identifier, a constant, a string literal, or a symbol. For example, the GO statement below consists of six tokens:

Copy Code code as follows:

Fmt. Println ("Hello, world!")

Individual tokens are:
Copy Code code as follows:

Fmt
.
Println
(
"Hello, world!."
)

Row Separator
In the Go program, the key to a line delimiter is a statement termination. In other words, each individual statement does not require a special divider line; Where the C compiler is transferred to the interior; Represents the end of a logical entity as a statement terminator.

For example, here are two different statements:

Copy Code code as follows:

Fmt. Println ("Hello, world!")
Fmt. Println ("I AM in Go programming world!")


notes
Comments are just like help text in your go program, and they are ignored by the compiler. They start using the character/* and terminate the use * as shown in the following image:

Copy Code code as follows:

/* My A/I/*


Annotations cannot be included in comments, and they cannot appear in a string or character text.

Identifier
The go identifier is used to identify variables, functions, or any other user-defined project name. An identifier begins with a letter A through Z or a to Z or underscore _ followed by 0 or more letters, underscores and numbers (0〜9).

Copy Code code as follows:

Identifier = Letter {letter | unicode_digit}.


The go language does not allow punctuation characters in identifiers, such as @,$ and%. Go is a case-sensitive programming language. So, Manpower and Manpower are two different identifiers on go. Here are some examples of acceptable identifiers:

Copy Code code as follows:

Mahesh KUMAR ABC Move_name a_123
Myname50 _temp J A23b9 RetVal


Key Words
The following list shows the reserved word for go. These reserved words may not be used as constants or variables, or any other identifier name.

Blank grid in Go
contains only spaces, possibly with comment lines, is called a blank line, and the go compiler completely ignores it.

Whitespace is used in go to describe spaces, tabs, line breaks, and annotation terms. A space is separated from another part of the declaration so that the compiler can find an element in a declaration, such as an int, ending with the next element starting. So, in the following statement:

Copy Code code as follows:

var age int;


You must have at least one white-space character (usually a space) between the int and the age compiler so that you can distinguish between them. On the other hand, in the following statement:

Copy Code code as follows:

Fruit = apples + oranges; Get the total fruit


No white-space characters are necessary, fruit and = between or = and apples, although it is free, if you want to facilitate the reading of the purpose, it is best to include some spaces.

Go Language data type
in the Go programming language, data types refer to a wide range of systems for declaring variables or different types of functionality. The type of the variable determines how much space occupies the storage and storage way the bit pattern will be interpreted.

The data types of go can be categorized as follows:

Array types and struct types are collectively referred to as aggregation types. The type of the function specifies a set of all functions that have the same parameters and result types. We will see the basic type in the following section, while the other types will be included in the later chapters.

Integral type
the predefined schema-independent integer types are:

Floating-point types
the predefined schema-independent floating-point types are:

The value of n-bit integers is n-bit and is represented by the complement arithmetic operation of 2.

Other numeric types
There is also a set of numeric types and the exact size of the execution:

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.