您的位置 首页 golang

Golang基础之变量

变量可以理解为内存地址的别名,用来定义一块内存存储空间和使用这块内存。

Golang基础之变量

1、变量命名规范

变量的命名规则遵循骆驼命名法,即首个单词小写,之后每个新单词的首字母大写,例如:dataStatus。

public的变量必须大写字母开头,private变量则以小写字母开头。

2、使用变量

 var name string
var city string="beijing"
var age = 18
name := "jon"  // 简短声明语法,在函数体内部声明局部变量时使用  

3、一次性声明多个变量

 var name, age, city
name, age, city := "jon", 18, "beijing"

var (
name = "jon"
age = 18
city = "beijing"
)  

4、匿名变量

 _, err := GetProcess()  

5、查看变量数据类型和占用内存大小

 var name string = "tom"

fmt.Printf("变量name的类型: %T ,占用的字节数是:%dn", name, unsafe.Sizeof(name))  

由于string是程序的数据类型,由go的结构体实现,这个结构体包含两部分:一部分是指向字符串起始地址的指针,另一部分是字符串的长度,两部分各是8字节,所以一共16字节

6、 变量可以是任何类型

 var v1 []int  // 切片
var v2 [10]string // 数组
var v3 struct{name string} // 结构体
var v4 *int64 // 指针
var v5 map[string]string // map
var v6 func(name string) (int, error) // 函数  

文章来源:智云一二三科技

文章标题:Golang基础之变量

文章地址:https://www.zhihuclub.com/97886.shtml

关于作者: 智云科技

热门文章

评论已关闭

30条评论

  1. Taken together, these results indicate that only a small fraction of Bmi1 tumorigenic cells survived and continued to clonally proliferate independently of each other It is therefore inappropriate to reach conclusions about the relative efficacy of agents on the basis of cross trial comparisons

  2. OFS can be accomplished with gonadotropin releasing hormone agonists GnRHa such as goserelin or leuprolide, which are injected monthly, or with surgical oophorectomy

  3. Topical formulations can also include an oil phase including, for example, oil phase which, in turn, may include emollients, fatty alcohols, emulsifiers, combinations thereof, and the like

  4. Por Visitante, Maio 17, 2017 Г s 16 36 em Relatos Even if a woman already has breast cancer, I don t think she needs to worry about going into a Chinese restaurant and having a tofu dish

  5. However, these were not associated with outcome after radiotherapy in the TCGA breast cancer cohort

  6. The glycemic index ranks carbs based mostly Blood Sugar Levels Chart vaginal discharge high blood sugar on how they have an result on blood sugar levels Ranging from zero to a hundred, the scale lets you perceive how shortly and how much a certain carbohydrate raises blood sugar ranges These meals are excessive in fiber, moderate in fats, and comprise healthy carbs Though simple carbohydrates are not recommended for these vaginal discharge high blood sugar Symptoms Of High Blood Sugar with high blood pressure, complex carbohydrates like bananas, oatmeal, and sweet potatoes provide needed vitamins like fiber There are instances where uncontrolled blood sugar ranges also lead to vomiting in some patients As glucose begins to construct up within the bloodstream, it puts stress on vaginal discharge high blood sugar the kidneys

  7. I am sure she will be vindicated, especially with Teresa saying on the record she didnГў t sign many of the applications presented to her, and Joe telling the court he signed her name, Гў said Penny Drossos Karagiorgis, owner of Le Chateau Allure salon in Englewood, scene of many Гў HousewivesГў meetings

  8. Recently, 78 miRNAs were identified to be differentially expressed between MCF 7 and 2A cells including the ER regulated let 7c, miR 99a, and miR 125b supporting a putative role in endocrine resistance 27 Assuming that women who undergo PBSO for risk reduction only take hormone replacement therapy until their natural menopause, no increased risk from hormone replacement therapy e

  9. Indeed, Jernigan and Drummond 38 have shown that epithelial sodium channels may serve as mechanosensors for myogenic vasoconstriction of upstream renal arteries, but this has been contested recently by Wang et al

  10. 1 Department of Nuclear Medicine, Inselspital, Bern University Hospital, University of Bern, Bern, Switzerland; and

  11. My dog took gabapentin for arthritis for a few days and it really helps The New Rules of Feed Antibiotics

  12. Zhao Ling said directly to the Queen Mother furosemide and blood sugar who was hiding at the base

  13. Tamoxifen only induced substantial death similar to that of SC D F9 in 48 h at high concentration 15 ВµM

  14. Effect of omega 3 fatty acids supplementation on depressive symptoms and on health related quality of life in the treatment of elderly women with depression a double blind, placebo controlled, randomized clinical trial

  15. In fact, CN is the third leading cause of new acute renal failure in hospitalized patients 1

  16. He also knows he gets a treat when it s medicine time It is estimated that in 2020, there were 81, 400 new cases of bladder cancer, accounting for 4

网站地图