当前位置:网站首页>Go language -- language constants
Go language -- language constants
2022-07-06 05:39:00 【Clear breeze and bright moon Li】
/*
1.go Language constants
A constant is a simple identifier , When the program is running , The amount that will not be modified
Data types in constants can only be Boolean , Digital ( plastic 、 Floating point and complex Numbers ) And string .
The definition format is
const b type = value
2. According to the omitted type specifier [type], Infer the type of a variable according to its value .
Display type definition : const b string = “abc”
Implicit type definition : const b = “abc”
Multiple declarations of the same type can be abbreviated as :
const a, b = value1 , value2
package main
import “fmt”
func main(){
const Length int = 200
const WIDTH int = 5
var area int
const a,b,c = 1, false, “str”
area = Length * WIDTH
fmt.Printf(“ Area is :%d”, area)
println()
println(a,b,c)
}
*/
/*
package main
import “unsafe”
const (
a = "ab
b = len(a)
c = unsafe.Sizeof(a)
)
func main(){
println(a,b,c)
}
*/
/*
3.go Language operators
Operators are used to perform data or logical operations while the program is running
go The language's built-in operators are :
Arithmetic operator (±*% ++ —- /)
Relational operator (== != > < >= <= )
Logical operators (&& And || or ! Not )
An operator ( Operate on the binary bits of integers in memory )
Assignment operator (= += -= *= /= %= <<= >>= &= ^= |=)
Other operators (& Return variable storage address * Pointer to the variable )
// Arithmetic operator
package main
import “fmt”
func main() {
var a int = 21
var b int = 10
var c int
}
package main
import “fmt”
func main() {
var a int = 21
var b int = 10
if ( a == b) {
fmt.Printf(“ first line - a be equal to b\n”)
} else {
fmt.Printf(“ first line - a It's not equal to b\n”)
}
if (a < b) {
fmt.Printf(“ The second line - a Less than b \n”)
} else {
fmt.Printf(“ The second line - a Not less than b \n”)
}
if ( a > b) {
fmt.Printf(“ The third line - a Greater than b \n”)
}
a = 5
b = 20
if ( a <= b ) {
fmt.Printf(“ In the fourth row - a Less than or equal to b\n” )
}
if ( b >= a ) {
fmt.Printf(“ The fifth row - b Greater than or equal to a\n” )
}
}
// Logical operators
package main
import “fmt”
func main() {
var a bool = true
var b bool = false
if ( a && b) {
fmt.Printf(“ first line - Condition is true\n”)
}
if ( a || b) {
fmt.Printf(“ The second line - Condition is true\n”)
}
}
// An operator . Bit operators operate on binary bits of integers in memory .& , | ,^
package main
import “fmt”
func main(){
var a uint = 60
var b uint = 13
var c uint = 0
c = a ^ b
fmt.Printf(“ first line -c The value of is %d”,c)
}
// Assignment operator , Simple assignment operators , Assign the value of an expression to an lvalue
A little
// Other operators ,& Return variable storage address ,&a The actual address of the variable will be given ,* Pointer to the variable ,*a Is a pointer variable .
package main
import “fmt”
func main() {
var a int = 4
var b int32
var c float32
var ptr *int
fmt.Printf(“ first line - a The variable type is = %T\n”, a )
fmt.Printf(“ The second line - b The variable type is = %T\n”, b )
fmt.Printf(“ The third line - c The variable type is = %T\n”, c )
}
*/
// Operator precedence . Operators have precedence , The operation direction of binary operators is from left to right ,*/<< >> & &^ > =-|^ > == != < > > && > || You can use parentheses to raise the overall operator priority of an expression
package main
import “fmt”
func main() {
var a int = 20
var b int = 10
var c int = 15
var d int = 5
var e int ;
e = (a+b) * c /d;
fmt.Printf(“(a + b) * c / d The value of is : %d\n”, e );
e = ((a + b) * c) / d; // (30 * 15 ) / 5
fmt.Printf(“((a + b) * c) / d The value of is : %d\n” , e );
e = (a + b) * (c / d); // (30) * (15/5)
fmt.Printf(“(a + b) * (c / d) The value of is : %d\n”, e );
e = a + (b * c) / d; // 20 + (150/5)
fmt.Printf(“a + (b * c) / d The value of is : %d\n” , e );
}
边栏推荐
- 28io stream, byte output stream writes multiple bytes
- Select knowledge points of structure
- 04. 项目博客之日志
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- [detailed explanation of Huawei machine test] check whether there is a digital combination that meets the conditions
- Installation de la Bibliothèque de processus PDK - csmc
- Sequoiadb Lake warehouse integrated distributed database, June 2022 issue
- 指针经典笔试题
- js Array 列表 实战使用总结
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
猜你喜欢
![[mask requirements of OSPF and Isis in multi access network]](/img/7d/1ba80bb906caa9be4bef165ac26d2c.png)
[mask requirements of OSPF and Isis in multi access network]

Vulhub vulnerability recurrence 71_ Unomi

04. 项目博客之日志

Vulhub vulnerability recurrence 69_ Tiki Wiki

Codeforces Round #804 (Div. 2) Editorial(A-B)

02. Develop data storage of blog project

Rustdesk builds its own remote desktop relay server

Unity Vector3. Use and calculation principle of reflect

Pix2pix: image to image conversion using conditional countermeasure networks

First acquaintance with CDN
随机推荐
What impact will frequent job hopping have on your career?
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
[QNX Hypervisor 2.2用户手册]6.3.3 使用共享内存(shmem)虚拟设备
Installation de la Bibliothèque de processus PDK - csmc
Pix2pix: image to image conversion using conditional countermeasure networks
Pointer classic written test questions
Auto.js学习笔记17:基础监听事件和UI简单的点击事件操作
UCF (summer team competition II)
js Array 列表 实战使用总结
Easy to understand IIC protocol explanation
In 2022, we must enter the big factory as soon as possible
2022半年总结
清除浮动的方式
Web Security (VI) the use of session and the difference between session and cookie
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
C Advanced - data storage (Part 1)
无代码六月大事件|2022无代码探索者大会即将召开;AI增强型无代码工具推出...
[QNX hypervisor 2.2 user manual]6.3.3 using shared memory (shmem) virtual devices
Self built DNS server, the client opens the web page slowly, the solution
Anti shake and throttling are easy to understand