A case study of structural grammar in go language _golang

Source: Internet
Author: User

This example describes the structural grammar in the go language. Share to everyone for your reference. The specific analysis is as follows:

The structure grammar represents the new allocation of a struct by the value of the Structure field as a list.
Use the Name: syntax to list only some of the fields. (The order of the field names is irrelevant.) )
The special prefix & constructs a pointer to the structure grammar.

Copy Code code as follows:
Package Main
Import "FMT"
Type Vertex struct {
X, Y int
}
VAR (
p = vertex{1, 2}//has type Vertex
Q = &vertex{1, 2}//has type *vertex
r = vertex{x:1}//y:0 is implicit
s = vertex{}//x:0 and y:0
)
Func Main () {
Fmt. Println (P, Q, R, s)
}

I hope this article will help you with your go language program.

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.