当前位置:网站首页>2-GO variable operation
2-GO variable operation
2022-04-23 14:40:00 【Endless character】
Catalog
One 、 Introduction of variables
- What is a variable : Variables are used to describe the data storage space in the computer
- Role of variables : Is to save data in computer memory
- Declaration of variables :
var Variable name type
package main
import "fmt"
func main() {
var age int
var num, sum int
fmt.Println(age)
fmt.Println(num)
fmt.Println(sum)
}
- Variable initialization : You can assign values to variables when you define them , This process initializes variables
package main
import "fmt"
func main() {
var age int = 10
var num int = 20
fmt.Println(age, num)
}
- Variable assignment : After the variable is defined , And assign values to variables , That is, declaration before assignment
func main() {
var a int = 10
var b int
b = a
fmt.Println(b)
}
- Case study : In exchange for 2 Values of variables
func main() {
var num1 int = 10
var num2 int = 20
var temp int
temp = num1
num1 = num2
num2 = temp
fmt.Println(num1, num2)
}
- Automatic derivation type : The so-called automatic derivation type , Just don't go through var Declare variables , Don't specify type , Directly follow the variable name with ”:” Number , Complete the assignment at the same time . that GO The type of variable will be automatically deduced according to the assigned value . If num The variable is assigned a decimal number , Then the type of the variable is decimal ( floating-point )
func main() {
num := 10
num1 := 20
a, b, c :=12, 13, 14
fmt.Println(num, num1)
fmt.Println(a, b, c)
}
- Case study : In exchange for 2 Values of variables ( Realization 2)
func main() {
num1 := 10
num2 := 20
num1, num2 = num2,num1
fmt.Println(num1,num2)
}
Two 、 Input and output format control
- Println: Formatted output
- Printf: Format output ,
%d
Indicates that the output is the value in an integer variable ,\n
Means line break
func main() {
num1 := 10
num2 := 20
num3 := 30
fmt.Println(num1, num2, num3)
fmt.Println("num1=", num1)
fmt.Printf("num1 = %d\n", num1)
fmt.Printf("num2 = %d,num3 = %d",num2, num3)
}
- Scanf:Scanf() Grammar format :fmt.Scanf(“%d”,&num)
- Scan:Scan() Grammar format : fmt.Scan(&num)
- Variable address : In memory, corresponding storage units will be opened up for variables , In order to be able to find the storage unit, access data , The system will add a number to each unit , This number is the address
- Scan and Scanf The difference between :Scan You do not need to specify a formatter , later stage Scan More frequently used
package main
import "fmt"
func main() {
var age int
fmt.Println(" Please enter age :")
/* fmt.Scanf("%d",&age) // adopt Scanf The function assigns the data entered by the keyboard to the variable , But variables must be preceded by & fmt.Println("age = ",age) fmt.Println(&age) fmt.Printf("%p",&age) */
fmt.Scan(&age)
fmt.Println("age = ", age)
}
3、 ... and 、 Computer base system
A simple understanding of , And there are a lot of information on the Internet , Including binary conversion and so on
- What is base : The method of counting according to the principle of carry is called carry counting system .“ Carry numeration system ” Referred to as “ Number system ” or “ Base number ”
- The carry of each number system follows a rule , That's it ---- Meet N Into the 1
- Hexadecimal features
- Use a fixed set of numbers to represent the size of the value . Such as : The decimal number is 0,1,2,3,4,5,6,7,8,9
- Uniform rules : Meet N Jin Yi
- Binary element
- base : there N It's called cardinality . So-called “ base ” It refers to the number of basic digits allowed in various binary counting systems
- Position right :215=2*102 + 1*101 + 5*100 , among 102 , 101 ,100 Position right
- Add by weight : Multiply the numeric character on each bit by the weight it represents
Four 、 Variable naming conventions
- Naming specification
- ①. Only numbers , Letter ,_( Underline ) form
- ②. Cannot start with a number
- ③. Capital letters and lowercase letters are different :heapSort and Heapsort It's two different names
- ④. It can't be a keyword
- Naming rules
- Hump nomenclature
- Little hump nomenclature (lower camel case): The first word begins with a lowercase letter ; The first letter of the second word is capitalized , for example : myName、aDog
- Big hump nomenclature (upper camel case): The first letter of each word is capital , for example :FirstName、 LastName
- Underline separation : Multiple word names , Write in all lowercase letters , In the middle _ Separate , for example :first_name、user_name
- Hump nomenclature
版权声明
本文为[Endless character]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231437070977.html
边栏推荐
- 【工厂模式详解】工厂方法模式
- 【无标题】
- PWM speed regulation control system of DC motor based on 51 single chip microcomputer (with complete set of data such as Proteus simulation + C program)
- 流程控制之分支语句
- vscode中文插件不生效问题解决
- Find daffodils - for loop practice
- 【Servlet】Servlet 详解(使用+原理)
- 51 Single Chip Microcomputer Design of traffic light system (with Proteus simulation, C program, schematic diagram, PCB, thesis and other complete data)
- Nacos uses demo as configuration center (IV)
- 四层和八层电梯控制系统Proteus仿真设计,51单片机,附仿真和Keil C代码
猜你喜欢
UML项目实例——抖音的UML图描述
C语言知识点精细详解——数据类型和变量【1】——进位计数制
利用 MATLAB 编程实现最速下降法求解无约束最优化问题
1 minute to understand the execution process and permanently master the for cycle (with for cycle cases)
SHT11传感器的温度湿度监控报警系统单片机Proteus设计(附仿真+论文+程序等)
数组模拟队列进阶版本——环形队列(真正意义上的排队)
OC 转 Swift 条件编译、标记、宏、 Log、 版本检测、过期提示
基于单片机的DS18B20的数字温度监控报警系统设计【LCD1602显示+Proteus仿真+C程序+论文+按键设置等】
51单片机的直流电机PWM调速控制系统(附Proteus仿真+C程序等全套资料)
电容
随机推荐
顺序表的操作,你真的学会了吗?
LLVM - 生成 if-else 以及 PH
capacitance
单相交交变频器的Matlab Simulink建模设计,附Matlab仿真、PPT和论文等资料
1 minute to understand the execution process and permanently master the for cycle (with for cycle cases)
Electronic scale weighing system design, hx711 pressure sensor, 51 single chip microcomputer (proteus simulation, C program, schematic diagram, thesis and other complete data)
八路抢答器系统51单片机设计【附Proteus仿真、C程序、原理图及PCB文件、元器件清单和论文等】
Proteus simulation design of four storey and eight storey elevator control system, 51 single chip microcomputer, with simulation and keil c code
ASEMI超快恢复二极管与肖特基二极管可以互换吗
外包干了四年,废了...
C语言知识点精细详解——初识C语言【1】——你不能不知的VS2022调试技巧及代码实操【1】
Matrix exchange row and column
矩阵交换行列
AT89C51 MCU digital voltmeter development, measuring range 0 ~ 5V, proteus simulation, schematic diagram, PCB and C program, etc
C语言知识点精细详解——初识C语言【1】
51 MCU + LCD12864 LCD Tetris game, proteus simulation, ad schematic diagram, code, thesis, etc
【JZ46 把数字翻译成字符串】
Basic regular expression
SVN详细使用教程
SHT11传感器的温度湿度监控报警系统单片机Proteus设计(附仿真+论文+程序等)