Go Language Example: Constants

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

the constants supported by the go language are character, String, Boolean, and numeric.



Use the const keyword to define constants.

where you can have a var statement, you can have a const statement.

constant expressions can be computed with arbitrary precision. Constants are of no type unless there are statements given, such as coercion of type conversions.

numeric constants are automatically added to the type when the context requires it. For example, variable assignment or function call. The math in this example. Sin (n), sin

The function requires a int64 type, and n is automatically converted to int64.

Plain Text Code ?
123456789101112 package main import " FMT "import " math "const s string = " constant "func main ()  {     fmt. Println (s)      const n = 500000000      const d = 3e20 / n      fmt. Println (d)      fmt. PRINTLN (Int64 (d))      fmt. Println (Math. Sin (n)) }


$ go Run constant.go  
constant
6e+11
600000000000
-0.28470407323754404


Original link:Https://gobyexample.com/constants
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.