有什么*和&放大器之间的差C编程运营商? [英] What is the difference between the * and the & operators in c programming?

查看:82
本文介绍了有什么*和&放大器之间的差C编程运营商?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是确保我正确地理解这个概念。与*运算符,我提出一个新的变量,被分配在内存中的地方。从而不会不必要地重复变量及其值,所述&放大器;运营商是在传承价值的方法和使用这样的,它实际上指向变量的原始实例,而不是制造新副本......是吗?这显然​​是一个粗浅的认识,但我只是想确保我不会让他们混在一起。谢谢!

I am just making sure I understand this concept correctly. With the * operator, I make a new variable, which is allocated a place in memory. So as to not unnecessarily duplicate variables and their values, the & operator is used in passing values to methods and such and it actually points to the original instance of the variable, as opposed to making new copies...Is that right? It is obviously a shallow understanding, but I just want to make sure I am not getting them mixed up. Thanks!

推荐答案

不太。你混淆一个 * 出现在一个类型名(用来定义一个变量),用 * 运营商

Not quite. You're confusing a * appearing in a type-name (used to define a variable), with the * operator.

int main() {
    int i;    // i is an int
    int *p;   // this is a * in a type-name. It means p is a pointer-to-int
    p = &i;   // use & operator to get a pointer to i, assign that to p.
    *p = 3;   // use * operator to "dereference" p, meaning 3 is assigned to i.
}

这篇关于有什么*和&放大器之间的差C编程运营商?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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