Go - Constants
Constants may be of any of the basic statistics sorts like an integer consistent, a floating consistent, a character constant, or a string literal.
An integer literal can be a decimal, octal, or hexadecimal regular. A prefix specifies the base or radix: 0x or 0X for hexadecimal, zero for octal, and nothing for decimal.Here are a few examples of integer literals
212 /* Legal */ 215u /* Legal */ 0xFeeL /* Legal */ 078 /* Illegal: eight isn't an octal digit */ 032UU /* Illegal: can not repeat a suffix */
Floating-point LiteralsA floating-factor literal has an integer part, a decimal point, a fractional element, and an exponent part. The signed exponent is brought by way of e or E.
3.14159 /* Legal */ 314159E-5L /* Legal */ 510E /* Illegal: incomplete exponent */ 210f /* Illegal: no decimal or exponent */ .E55 /* Illegal: lacking integer or fraction */
Escape SequenceSequence codes that are used to represent newline (n), tab (t), backspace, etc.
|"||" man or woman|
|a||Alert or bell|
|ooo||Octal range of one to a few digits|
|xhh . . .||Hexadecimal variety of 1 or more digits|
The following example suggests how to use t and " in a application
package deal essential import "fmt" func important() fmt.Printf("HellotWorld! "welookups" ")
$pass run foremost.Pass Hello World! "Welookups"
String Literals in GoString literals or constants are enclosed in double charges "".A string includes characters that are much like man or woman literals: undeniable characters, get away sequences, and accepted characters.
"hiya, MASTER" "hiya, pricey" "whats up, " "M" "ASTER"
The const KeywordYou can use const prefix to claim constants with a selected type as follows
const variable kind = cost;The following example shows the way to use the const keyword
package deal main import "fmt" func most important() const LENGTH int = 12 const WIDTH int = 6 var location int location = LENGTH * WIDTH fmt.Printf("price of region : %d", location)When the above code is compiled and finished, it produces the following result
$pass run foremost.Pass fee of place : 72