Golang Study Notes

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

differs from C syntax:

 1. You can only write the last one, such as: Add (x, y int) int {return x +y} 2, in the parameter list when each parameter type is the same. Type after parameter name (variable/function) 3. The opening brace of the function is the same line as the function name, otherwise the compilation is not 4. function definition to write the keyword Func at the beginning of the function (each statement outside the function must start with the Func, Var, and so on) 5. Use the VAR statement when declaring variables at the package or function level 6. The function supports multi-value returns, such as: Func swap (x, y String) (string, String) {return y,x} 7. The function supports naming return values such as Func split (x int) {... return} 8. Initialization using an expression can be used without a write type, derived from the initial value of type 9. You can use: = To implement the variable simple copy, do not need to add Var, but only within the function of 10.FMT. printf formatted output:%t output variable type,%Q output string with double quotation marks,%V output structure type 11. The assignment of different types of variables requires display type conversion 12. Constant definition to use const, cannot use: =, declare two const variable can be const (x=1; y= 2) 13. Conditional control statements without parentheses (if, for, switch, etc.) 14.for Loop Pre-and post-statement can be empty, such as for sum < 1000 {...}, the format similar to while,for in C is empty when the loop condition is dead loop 15. If statement can be added a convenient statement, such as if v:=41; The variables declared in the SUM&LT;LIM{...},IF convenience statement are valid only in the IF statement and the Else statement 16.switch...case ... It stops when the match succeeds, does not need to show break like C, and the conditional switch statement is equivalent to switch true for clearer expression of the if-then-else 17.defer keyword, delaying the execution of the statement until the upper function returns, The deferred function is pressed into the stack, the LIFO 18.go has pointers, but there is no pointer operation, and the pointer accesses the struct member by using the dot operator, which is transparent 19. By name: syntax You can list only a subset of fields, and the remaining fields are zero values of 20. Create Slice B: = Make ([ ]int, 0, 5)//Len (b) =0, Cap (b) =5,make parameters include length and capacity, slice 0 value is nil, and a nil slice length and capacity are 0 21.go If there is a declaration but not used variables compile will error, use _ to do the variable name can be 22.go without classes, but can be in the package arbitrary type definition method (excluding the underlying type) 23. Methods can be associated with a named type or a pointer to a named type, and the recipient is a pointer with two benefits: first, Avoid copying a value in a method call, and second, you can modify the value that the recipient points to 24. The interface type is a collection of types defined by a set of methods, and the values of the interface types can hold any value that implements these methods 25. See Official go language documents locally, godoc-http=:8011 (Specify the port number), And then the browser opens http://localhost:8011.

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.