Go language Learning (ii) constants

Source: Internet
Author: User
Tags constant definition
This is a creation in Article, where the information may have evolved or changed.
 PackageMainImport "FMT"//1. Keyword const for defining constantsConstPifloat64=3.14159265358979323846ConstZero =0.0 //No type floating-point constantConst(SizeInt64=1024x768EOF =-1  //non-type integral constant)ConstU,vfloat32=0,3 multiple assignments of//u=0.0,v=3.0 constantsConstA, b, C =3,4,"foo" //a=3,b=4,c= "foo" untyped integral type and character constants//Go's constant definition can qualify a constant type, but is not required. If you define a constant without specifying a type, it//As with literal constants, there is no type constant. the right value of the//constant definition can also be a constant expression that is evaluated at compile time, such asConstMask =1<<3//2. Pre-defined constantsThe //go language is reserved for these constants: True,false and Iota//iota is a special, can be considered a compiler can be modified by a constant, when each const keyword appears to be reset to 0, and then the next const constant appears before the occurrence of a iota, each time it represents the number will be increased by 1Const(//iota is reset to 0C01 =Iota  //C01 = = 0C02 =Iota  //C02 = = 1C03 =Iota  //C03 = = 2)Const(//iota is reset to 0a0 =1<<Iota //a0 = = 1 (1 times 2 of 0 power)B1 =1<<Iota //B1 = = 2 (1 times 2 of 1 power)C1 =1<<Iota //C1 = = 4 (1 times 2 of 2 power))Const(//iota is reset to 0u1 =Iota* the //u1 = = 0V1float64=Iota* the //v1 ==42.0W1 =Iota* the //W1 ==84)ConstX1 =Iota //x1==0 because Iota was reset to 0.ConstY1 =Iota //y1==0 Ibid .//If the expression of the two Const assignment statement is the same, then the latter assignment expression can be omitted. Therefore, onthe first two const statements of//polygons can be abbreviated as:Const(C00 =IotaC11 C22)Const(A12 =1<<Iota //a12==1 (iota at each const start is reset to 0)B12//b12==2C12//c12==4)funcMain () {//Note: The declaration of a constant cannot be repeatedFmt. Println ("pi=", Pi) fmt. Println ("zero=", zero) fmt. Println ("Size=", size) fmt. Println ("eof=", EOF) FMT. Printf ("u=%v,v=%v\n", U,v) fmt. Printf ("a=%v,b=%v,c=%v\n", A,b,c) fmt. Printf ("c01=%v,c02=%v,c03=%v\n", C01,C02,C03) fmt. Printf ("a0=%v,b1=%v,c1=%v\n", A0,B1,C1) fmt. Printf ("u1=%v,v1=%v,w1=%v\n", U1,V1,W1) fmt. Printf ("x1=%v,y1=%v\n", X1,y1) fmt. Printf ("c00=%v,c11=%v,c22=%v\n", C00,C11,C22) fmt. Printf ("a12=%v,b12=%v,c12=%v\n", A12,B12,C12)}

Run results

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.