WEB DEVELOPER SITE

# 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.

## Integer Literals

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.

Constants can be of any of the basic data types like an integer constant, a floating constant, a character constant, or a string literal.

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 Literals

A 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 Sequence

When certain characters are preceded by a backslash, they will have a new character meaning in Go. Sequence codes that are used to represent newline (n), tab (t), backspace, etc. Here, you have a list of some of such escape sequence codes −
Escape series Meaning
individual
' ' individual
" " man or woman
? ? Person
a Alert or bell
b Backspace
f Form feed
n Newline
r Carriage return
t Horizontal tab
v Vertical tab
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" ")

```

### Output

```\$pass run foremost.Pass
Hello	World! "Welookups"
```

## String Literals in Go

String literals or constants are enclosed in double charges "".A string includes characters that are much like character literals: characters, escape sequences, and universal characters.

Here are some examples of string literals. All the three forms are identical strings.

```"hello, dear"

"hello, \

dear"

"hello, " "d" "ear"
```

## The const Keyword

You can use const prefix to claim constants with a specific type as follows
`const variable type = value;`
The following example shows the way to use the const keyword
```package main

import "fmt"

func main() {
const LENGTH int = 10
const WIDTH int = 5
var area int

area = LENGTH * WIDTH
fmt.Printf("value of area : %d", area)
}```

When the above code is compiled and executed, it produces the following result −

```value of area : 50
```

Note that it is a good programming practice to define constants in CAPITALS.