C/C++为什么结构体在函数中通过 地址传递,怎么输出地址不对 printf("top:%d\n",top);,麻烦从内存角度分析
#include
#include
struct node{
int data;
struct node *next;
};
struct stack{
struct node *top;
};
void push_l(struct node *s,int val)
{
struct node *p=(struct node *)malloc(sizeof(struct node));
p->data=val;
p->next=s;
s=p;
printf("s:%d,p:%d\n",s,p);
}
void main()
{
struct node top;
push_l(&top,3);
printf("top:%d\n",top);
printf("s.data:%d\n",top.data);
system("pause");
}