Daily Go Language Bible-scope, underlying data type, integer

Source: Internet
Author: User

Go Language Bible-scope

1. A declaration statement associates an entity in a program with a name, such as a function or a variable

2. The life cycle of a variable is the valid time period in which a variable exists when the program runs; the scope of the declaration statement corresponds to a text area of the source code, which is a compile-time property

3. Syntactic blocks are enclosed in curly brackets; we can extend the concept of blocks to groups that include other declarations that are not explicitly wrapped in code using curly braces, which we call lexical chunks.

4. Global scope Package-level syntax domain source file-level scope local scope function-level scope

5. Look for the global scope from the lexical domain of the most inner layer. The internal will overwrite the external, if the lookup fails, then the "Undeclared name" error is reported

6. A lexical domain can be deeply nested, so an internal declaration may mask External declarations

7. Implicit lexical domains, such as: For loop function nominal domain, one in for implicitly initialized lexical domain, one in for loop nominal domain

The 8.Go language habit is to handle errors in if and then return directly, which ensures that the normally executed statements do not require code indentation.

9. Pay special attention to the scope range of the short variable declaration statement, although the variable is declared externally, but: = statement or declare the variable as a new local variable

Avoid similar potential problems by declaring variables separately to avoid using: =

Go Language Bible-basic data types

1. Base type, composite type, reference type, and interface type

2. Underlying types, including: numbers, strings, and Booleans

3. Composite data Types-arrays (§4.1) and structs (§4.2)

4. Reference types include pointers (§2.3.2), slices (§4.2)) dictionaries (§4.3), Functions (§5), channels (§8), which are indirect references to a variable or state in a program

Go Language Bible-integral type

1.int8, Int16, Int32, and int64 four distinct-sized signed integer types

2.uint8, UInt16, UInt32, and UInt64 four types of unsigned integers

3. Signed and unsigned integers int and uint, where int is the most widely used numeric type. Both of these types have the same size, 32 or 64bit

4.byte is also an equivalence type for the uint8 type, and the byte type is typically used to emphasize that the value is an original data instead of a small integer

5. An unsigned integer type uintptr, with no specific bit size specified but sufficient to hold the pointer

6.bit-bit operation operator,& | ^ &^ bit empty (and not) << left shift >> right shift

7. The%b parameter of the printf function is used to print the binary format number, where 08 means printing at least 8 character width, and the insufficient prefix portion with 0 padding

&^ is by position 0 X&^y Press Y to place 0 x; x^y or on the basis of | or to remove two 1 parts

8. Prefer to use the signed int type, UINT unsigned type such as when the condition is judged at the time of the loop

9. Unsigned numbers are often used only by bitwise operations or other special operational scenarios

10. Type mismatch issues that require explicit type conversions, converting a large integer type to a small integer type, or converting a floating-point number to an integer, which may change the value or lose precision

11. Integer value can be written in octal format starting at 0, for example, 0666, written in hexadecimal format beginning with 0x or 0X, e.g. 0xdeadbeef

The%d,%o, or%x parameters control the output's binary format, and the [1] adverb after% tells the printf function to use the first operand again, and the% # adverb tells printf to generate a 0, 0x, or 0X prefix when outputting with%o,%x, or%x, and the characters are printed with the%c parameter, or in% Q-Parameter prints characters with single quotation marks

Daily Go Language Bible-scope, underlying data type, integer

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.