Go by Example: Constants

Source: Internet
Author: User

Go by Example: Constants

The Go language supports constants of character, String, Boolean, and numeric type variables.

Package mainimport "fmt" import "math" // use the keyword const to declare a constant const s string = "constant" func main () {fmt. println (s) // Where any var declaration can appear, you can use the const statement const n = 500000000 // a constant expression to execute any precision calculation. Const d = 3e20/n fmt. println (d) // a numeric constant has no type unless the corresponding type is given in the statement, for example, forced type conversion fmt. println (int64 (d) // according to the context of the statement, a numerical constant is assigned the corresponding type. For example, in variable declaration or function call // For example, if the function math. Sin () requires a float64 value, n is treated as a float64 value. Fmt. Println (math. Sin (n ))}
Output

$ Go run constant. go constant6e + 11600000000000-0.28470407323754404


Next example:.


Original ENGLISH


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.