Go-Basic Knowledge-data type-Constant

Source: Internet
Author: User

1. Constant: the so-called constant, that is, the value determined during the program compilation stage, and the value cannot be changed during the program running. In the go program, constants can be defined as numerical values, Boolean values, strings, and other types.

Example 1-> Syntax

 
ConstConstantname =Value//If needed, you can also specify the type of the constant:ConstPi float32 =3.1415926

Example 2-> More forms

ConstPi =3.1415926ConstI =10000ConstMaxthread =10ConstPrefix ="Astaxie _"

Example3-> simple call example

Package mainimport"FMT"ConstPi float64 =3.14Func main () {FMT. printf ("% V", Pi )}

Different from general programming languages, go constants can specify a considerable number of decimal places (for example, 200 BITs). If float32 is specified, it is automatically shortened to 32bit, and float64 is automatically shortened to 64bit.

 

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.