求帮助~~栈中传址的问题
链栈置空的时候,写(Snode *&st),Snode *不是已经表示传的是地址了吗?为什么还要加&??这样写到底是什么意思啊??
2012-11-25 21:35

2012-11-25 23:18
2012-11-26 22:16
程序代码://bccn.cpp
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
int yyy;
}Snode;
void Empty_p(Snode *s)
{
if (s)
{
free(s);
printf (" \tfree...... \n");
s = NULL;
}
}
void Empty_ref(Snode *&s)
{
if (s)
{
free(s);
printf (" \tfree...... \n");
s = NULL;
}
}
int main()
{
Snode *s = NULL;
Snode *t = NULL;
s = (Snode*) malloc(sizeof(Snode));
t = (Snode*) malloc(sizeof(Snode));
if (s)
{
printf ("s = %p\n", s);
Empty_p(s);
printf ("s = %p\n", s);
}
if (t)
{
printf ("t = %p\n", t);
Empty_ref(t);
printf ("t = %p\n", t);
}
return 0;
}
2012-11-26 23:40