Go language learning Notes-constants

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

Constant is the amount of time that the program will not change when it runs
The constants in go are declared in the same way as variables, with combination declarations, parallel declarations, general declarations

/** * 定义常量 */const (    PI                3.14//这里并没有声明变量类型,编译器会自行判断    "yyyy-mm-DD HH-mm-ss"    FORMAT  //不提供数据类型和初始化值得常量视作和上一个常量相同(赋值表达式) 即FORMAT = "yyyy-mm-DD HH-mm-ss"    10//给变量指定明确的类型)

The value of a constant can also be the return value of a function that can determine the return value for the compilation period, such as Len, cap, and unsafe. Sizeof

count{    astring"abc"    len(a)    c = unsafe.Sizeof(b)}

Meiju
Keyword Iota defines a 0-based self-increment enumeration value in a constant group

//enumeration     Const  (_ = iota  KB int64  = 1  <<  *  Iota ) //iota = 1, (1 <<) = = (1 * 1024x768)  MB //assignment expression omitted, ibid.  GB TB) const  (A, B = iota , iota  <<     //0, 0 <<  C, D //1, 1 << )  
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.