有谁能解释这个? [英] any body can explain this ?

查看:91
本文介绍了有谁能解释这个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include<iostream>
#include<conio.h>
using namespace std;

void AAA (int* & x,int *y)
{
    cout<<y<<endl;
    cout<<x<<endl;
}
    void main()
{
    int x=5;
    int *y=&x;

    AAA(y,y);
    getch();

}



{int *& x,int * y}



what is mean both of { int* & x,int *y }

推荐答案

int *是指向包含int的内存地址的指针. int * y =&x表示x和y都是SAME int实例,仅在此处创建一个int.但是,它的一个指针也被传递了两次,因为您两次传递了y,所以AAA中的x和y都在主对象中是y,因为这就是您传递的内容.

main总是在有效的C ++中返回int
int * is a pointer to a memory address that contains an int. int * y = &x means x and y are both the SAME int instance only one int is created here. However, its also the one pointer being passed twice, because you pass y twice, the x and y in AAA are both the y in your main, because that''s what you passed in.

main always returns int in valid C++


最好从右向左读取指针声明,以更好地理解!
int *& x 是对指向int
的指针的引用 int * y 是指向int
的指针
要了解更多信息,请查看此处:
http://stackoverflow.com/questions/5789806/含义-和-in-c [^ ]
http://stackoverflow.com/questions/4185776/what-does-mean- in-a-function-parameter [ ^ ]
http://stackoverflow.com/Questions/57483/pointer-variable-and-reference-variable-in-c [ ^ ]
Pointer declarations are better off to be read from right to left for better understanding!!
int* & x is a reference to a pointer to an int
int *y is a pointer to an int

To learn more, please look here:
http://stackoverflow.com/questions/5789806/meaning-of-and-in-c[^]
http://stackoverflow.com/questions/4185776/what-does-mean-in-a-function-parameter[^]
http://stackoverflow.com/questions/57483/what-are-the-differences-between-pointer-variable-and-reference-variable-in-c[^]


这篇关于有谁能解释这个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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