struct
定义: struct [名称]{…..};
初始化:
struct person{
int id ;
char *name;
};
方式一: struct person p1 = {100, "c"};
方式二:
struct person p1;
p1.id = 100;
对于普通的struct,使用.运算符赋值或取值,对于指针,使用->来赋值或取值
指针struct:
示例程序:
#include <stdio.h>
struct person{
int id ;
char *name;
};
void show(struct person *p){
p->id = 1000;
printf("id = %d, name = %s\n", p->id, p->name);
}
void main(){
struct person p1 = {100, "c"};
show(&p1);
}