星号在“执行"中起什么作用? [英] What does the asterisk do in "Go"?

查看:30
本文介绍了星号在“执行"中起什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一位网络开发人员,希望扩大自己的视野,以便更好地整体编程.我做了一些Java和一些简单的Android应用程序.我现在正在研究像C和Go这样的低级语言(到目前为止,我不得不说它具有一些漂亮的语法和很棒的主意,尽管我可能没有足够的经验来评论).

I'm a web developer looking to expand my horizons in order to get better at programming as a whole. I've done a bit Java and some simple Android applications. I'm now looking into lower level languages like C and Go (which I must say has some beautiful syntax and great ideas thus far, though I'm maybe too inexperienced to comment).

是的,我一直在尝试并尝试理解转到网站上的示例,而在这样的示例中,我不断遇到一个特殊的星号字符:

So yeah I've been going through and trying to understand the examples on the Go website and I keep coming across a special asterisk character in examples like this:

s := "hello"
if s[1] != 'e' {
    os.Exit(1)
}
s = "good bye"
var p *string = &s
*p = "ciao"

此外,我刚刚注意到,&s是什么?它是按引用分配的吗(我可能在这里使用PHP说话)?

Also, I just noticed, what's with the &s? Is it assignment by reference (I might be using PHP talk here)?

推荐答案

我猜它的含义与C中的含义相同

Im guessing it means the same as in C

p is a pointer to a string

语句var p *string = &s会将s对象的地址分配给p

The statement var p *string = &s would assign the address of the s object to p

下一行*p = "ciao"将更改s

请参见语言设计常见问题解答

有趣的是,没有指针算术

Interestingly, no pointer arithmetic

为什么没有指针算术? 安全.没有指针算术 可以创造一种语言 永远不会衍生出非法 错误地成功发送的地址. 编译器和硬件技术都有 前进到循环的地步 使用数组索引可以是 高效使用指针循环 算术.另外,缺少指针 算术可以简化 垃圾的实现 收藏家.

Why is there no pointer arithmetic? Safety. Without pointer arithmetic it's possible to create a language that can never derive an illegal address that succeeds incorrectly. Compiler and hardware technology have advanced to the point where a loop using array indices can be as efficient as a loop using pointer arithmetic. Also, the lack of pointer arithmetic can simplify the implementation of the garbage collector.

现在我想开始学习GO!

Now I want to start learning GO!

这篇关于星号在“执行"中起什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆