day 2. 结构体与指针两种引用的方法

来源:互联网 发布:understand mac注册码 编辑:程序博客网 时间:2024/06/06 00:17
#include <stdio.h>
#include <string.h>
struct Student
{
 int sid;
 char name[200];
 int age;
};                                                              //分号不能省;
void f(struct Student * pst);
void g(struct Student st);
void g2(struct Student * pst);
int main (void)
{
 struct Student st;
 
 f(&st);
 zhi2(&st);
 
 //printf("%d %s %d\n",st.sid,st.name,st.age);
 
 return 0;
}
void zhi1(struct Student st)                           //内存,不建议使用
{
 printf("%d %s %d\n",st.sid,st.name,st.age);
 
}
void zhi2(struct Student * pst)
{
 printf("%d %s %d\n",pst->sid,pst->name,pst->age);
 
}

void f(struct Student * pst)
{
 (*pst).sid=99;
 strcpy(pst->name,"zhangsan");
 pst->age=23;
}



阅读全文
0 0
原创粉丝点击