结构体作为函数参数
2016-10-23 本文已影响3人
PZcoder
结构体作为函数参数
struct teacher
{
char *name;
char score;
};
typedef struct teacher Teacher;
void printTeacher(Teacher * t)
{
printf("%s\n",t->name);
}
int main(int argc, const char * argv[])
{
@autoreleasepool
{
//结构体指针变量
//->结构体指针专用符号 寻址符
Teacher * p1=(Teacher *)malloc(sizeof(Teacher));//分配内存空间
p1->name = "pan";
p1->score = 100;
(*p1).name ="zhenze";
(*p1).score =100;
printTeacher(p1);
}
return 0;
}