int main(int argc, const char * argv[]) {
struct Person{
char *name;
int age;
};
//结构体变量
struct Person p1={"apple",24};
printf("name=%s,age=%d\n",p1.name,p1.age);
//结构体指针
struct Person *p=&p1;
printf("%s,%d\n",(*p).name,(*p).age);
//另一种写法:
// 结构体独有的箭头 printf("%s,%d\n",p->name,p->age);
//结构体数组
struct Person p2={"heima",22};
struct Person arr[2]={p1,p2};
printf("%s,%d\n",arr[0].name,arr[0].age);
return 0;
}
|
|