Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Basic syntax and built-in data types of the Go language

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "basic syntax and built-in data types of Go language". In daily operation, I believe that many people have doubts about the basic syntax and built-in data types of GE language. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "basic syntax and built-in data types of Go language". Next, please follow the editor to study!

Go token

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

The copy code is as follows:

Fmt.Println ("Hello, World!")

Individual tokens are:

The copy code is as follows:

Fmt

.

Println

(

"Hello, World!"

)

Line separator

In Go programs, the key to the line delimiter is the termination of a statement. That is, each individual statement does not require a special separator; where the C compiler goes inside, it represents the end of a logical entity as a statement Terminator.

For example, here are two different statements:

The copy code is as follows:

Fmt.Println ("Hello, World!")

Fmt.Println ("I am in Go Programming World!")

Annotation

Comments are like help text in your Go program, they are ignored by the compiler. They start using the characters / * and terminate the use of * / as shown in the following figure:

The copy code is as follows:

/ * my first program in Go * /

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

Identifier

The Go identifier is used to identify a variable, function, or any other user-defined project name. An identifier begins with the letters A to Z or a to z or underscore _ followed by zero or more letters, underscores, and numbers (0,9).

The copy code is 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. Therefore, Manpower and manpower are two different identifiers in Go. Here are some examples of acceptable identifiers:

The copy code is as follows:

Mahesh kumar abc move_name a_123

Myname50 _ temp j a23b9 retVal

Keywords

The following list shows the reserved words for Go. These reserved words can not be used as constants or variables, or any other identifier names.

Blank space 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 comment terms. Spaces are separated from the part of another declaration, enabling the compiler to find an element in a declaration, such as int, that ends and the next element begins. Therefore, in the following statement:

The copy code is as follows:

Var age int

There must be at least one white space character (usually a space) compiler between int and age in order to be able to distinguish between them. On the other hand, in the following statement:

The copy code is as follows:

Fruit = apples + oranges; / / get the total fruit

No white space characters are necessary, between fruit and = or between = and apples, although they are free, and if you want to make it easy to read, it's best to include some spaces.

Go language data type

In the Go programming language, data types refer to a wide range of systems used to declare variables or different types of functions. The type of variable determines how much space is occupied and the bit pattern of the storage mode will be interpreted.

The data types of Go can be classified as follows:

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

Integer type

Predefined schema-independent integer types are:

Floating point type

Floating-point types independent of predefined schemas are:

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

Other numerical types

There is also a set of number types and the specific size of the execution:

At this point, the study of "basic syntax and built-in data types of the Go language" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report