#include <iostream>
using namespace std;
//定义一个结构体
typedef struct node
{
int x;
}*tree;
void test(tree t) //定义一个函数,用地址做参数,分配地址,然后赋值
{
t=(tree)malloc(sizeof(node));
t->x =4;
printf("%d\n",t->x );
}
int main()
{
tree a=(tree)malloc(sizeof(node));
a->x =3; //先给a 分配地址,赋值3
test(a); //将a地址传入函数,想给a重新分配地址,然后赋值4
cout <<a->x;
}
它输出的值为:4和3,这个我还能理解,但是我把test函数改为void test(tree &t) //传别名,它的输出的值怎么又成了4和4?传别名跟传地址到底有什么区别呢??
谢谢。。。不太明白。。前者不也是传的址吗,怎么说是传的值呢?
谢谢,在线等。。。。