当前位置:网站首页>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
边栏推荐
- async void 导致程序崩溃
- SVN详细使用教程
- epoll 的 ET,LT工作模式———实例程序
- 查找水仙花数-for循环实践
- Sed learning for application
- LLVM - 生成加法
- Design of single chip microcomputer Proteus for temperature and humidity monitoring and alarm system of SHT11 sensor (with simulation + paper + program, etc.)
- 初识STL
- 8.2 文本预处理
- AT89C51 MCU digital voltmeter development, measuring range 0 ~ 5V, proteus simulation, schematic diagram, PCB and C program, etc
猜你喜欢
外包干了四年,废了...
关于在vs中使用scanf不安全的问题
【Servlet】Servlet 详解(使用+原理)
8.4 循环神经网络从零实现
金九银十,入职字节跳动那一天,我哭了(蘑菇街被裁,奋战7个月拿下offer)
成都控制板设计提供_算是详细了_单片机程序头文件的定义、编写及引用介绍
MCU function signal generator, output four kinds of waveforms, adjustable frequency, schematic diagram, simulation and C program
AT89C51单片机的数字电压表开发,量程0~5V,proteus仿真,原理图PCB和C程序等
Electronic perpetual calendar of DS1302_ 51 single chip microcomputer, month, day, week, hour, minute and second, lunar calendar and temperature, with alarm clock and complete set of data
Eight way responder system 51 Single Chip Microcomputer Design [with Proteus simulation, C program, schematic diagram, PCB files, component list and papers, etc.]
随机推荐
利用 MATLAB 编程实现最速下降法求解无约束最优化问题
全连接层的作用是什么?
一篇博客让你学会在vscode上编写markdown
c语言在结构体传参时参数压栈问题
单相交交变频器的Matlab Simulink建模设计,附Matlab仿真、PPT和论文等资料
Using MATLAB programming to realize the steepest descent method to solve unconstrained optimization problems
Model location setting in GIS data processing -cesium
拼接hql时,新增字段没有出现在构造方法中
Nacos uses demo as configuration center (IV)
【Proteus仿真】自动量程(范围<10V)切换数字电压表
1N5408-ASEMI整流二极管1N5408
Master in minutes --- ternary operator (ternary operator)
Swift:Entry of program、Swift调用OC、@_silgen_name 、 OC 调用Swift、dynamic、String、Substring
一个月把字节,腾讯,阿里都面了,写点面经总结……
Swift Protocol 关联对象 资源名称管理 多线程GCD 延迟 once
初始c语言大致框架适合复习和初步认识
Detailed explanation of C language knowledge points -- first knowledge of C language [1]
555定时器+74系列芯片搭建八路抢答器,30s倒计时,附Proteus仿真等
QT interface optimization: double click effect
On the insecurity of using scanf in VS