#include <stdio.h>
int main()
{
//定义结构体变量
struct Person{
char *name;//指针的方式定义字符串,指针指向常量区字符串首地址
int age;
};
struct Person p1 = {"abc",1};
struct Person p2 = {"def",2};
struct Person p3 = {"ghi",3};
struct Person persons[]={p1,p2,p3};;
//打印第一个元素name 第二个元素age
printf("%s\n%d\n",persons[0].name,persons[1].name);
return 0;
} |
|