当前位置:网站首页>PHP自学Go日记(四):GO的变量声明方式
PHP自学Go日记(四):GO的变量声明方式
2022-06-28 21:28:00 【游戏编程】
声明单个变量:
方式一:
var a int 该种声明方式用到关键词“var”,当中的“a”是变量名,“int”是变量类型。
由于并没有给变量赋值,因此变量的默认值是0、空、假。
方式二:
var b int = 100 该种声明方式在方式一的基础上,给变量赋值了。
方式三:
var c = 100 相较于方式二,这种方式并没有声明变量类型,初始化时由系统自动匹配
方式四:(常用)
d := 100 该方式省去关键词“var”,“=”前面添加“:”来代替,同样的系统自动变量类型
注:该方式仅能在函数体内使用,如果在函数外初始化一个变量,还是需要使用关键字“var”
声明多个变量:
方式一:
var xx, yy int = 100, 200 该方式仅适用于声明同一类型的变量
方式二:
var kk, ll = 100, "abcd" 该方式不声明变量类型,让系统自动匹配
方式三:(推荐)
var( vv int = 100 jj = false ) 该方式更有利于代码阅读,类型可写可不写,如果不写系统将自动匹配
补充:
// 用于打印变量类型fmt.Printf("type of a = %T\n", a) 以上代码可以打印变量的类型,fmt.Printf是Go格式化输出的方法,“%T”是占位符,代表打印值的类型。如果有多个占位符,需要后面以此传入多个变量。
除了“%T”,fmt.Printf还有很多占位符,想具体了解的可自行百度。
作者:KennyCCCC
游戏编程,一个游戏开发收藏夹~
如果图片长时间未显示,请使用Chrome内核浏览器。
边栏推荐
- The rogue downloader named by 315 is back
- Proficient in data analysis, double the income? What is the strongest competitiveness
- LeetCode116. Populate the next right node pointer for each node
- Can you make money by speculating in stocks? It's safe to open an account
- Bitbucket failed to pull the warehouse Using SSH
- [book club issue 13] packaging format of video files
- Leetcode: expand a binary tree into a linked list_ one hundred and fourteen
- 如何使用 DataAnt 监控 Apache APISIX
- LeetCode123. 买卖股票的最佳时机III
- Activate function
猜你喜欢

An artifact extracted from a well-known software and paid by a group of people

Postman introduction and installation steps

Anti rabbit dylight 488 abbkine universal immunofluorescence (if) toolbox

【筆記:模擬MOS集成電路】帶隙基准(基本原理+電流模+電壓模電路詳解)

The rogue downloader named by 315 is back

I almost ran away

【笔记:模拟MOS集成电路】带隙基准(基本原理+电流模+电压模电路详解)

Alist+raidrive gives the computer a complete 8billion GB hard disk drive

What is an interface? What is interface testing?

Biovendor free light chain( κ and λ) Test steps of ELISA Kit
随机推荐
Biovendor free light chain( κ and λ) Test steps of ELISA Kit
Study on bifunctional crosslinker lumiprobe sulfoacyanine 7 dicarboxylic acid
How to analyze the relationship between enterprise digital transformation and data asset management?
LeetCode1114. Print in sequence
Leetcode daily question - Sword finger offer II 091 Paint the house
Bitbucket 使用 SSH 拉取仓库失败的问题
Real time transformer: meituan's research on single image depth estimation
Leetcode: merge K ascending linked lists_ twenty-three
Bitbucket failed to pull the warehouse Using SSH
I almost ran away
【筆記:模擬MOS集成電路】帶隙基准(基本原理+電流模+電壓模電路詳解)
LeetCode117. 填充每个节点的下一个右侧节点指针_II
Web自动化工具选择
在哪个软件上开户比较安全,开户流程是什么?
LeetCode123. The best time to buy and sell stocks III
Understanding web automated testing
LeetCode每日一题——剑指 Offer II 091. 粉刷房子
LeetCode1114. 按序打印
Leetcode: merge two ordered linked lists_ twenty-one
Usage example of qjsonobject