结构体指针访问结构体成员
#include<stdio.h>#include<stdlib.h>
#include<string.h>
typedef struct
{
char a;
int b;
float c;
}struct_A_s;
typedef struct
{
char a;
int b;
struct_A_s obj;
float c;
}struct_B_s;
struct_B_s sObj =
{
10,
1000,
.obj.a = 10,
.obj.b = 1000,
.obj.c = 0.1,
9.99
};
int main()
{
struct_B_s *p = &sObj;
printf("a=%d\n",p->a);
printf("a=%d\n",p->b);
printf("obj-a=%d\n",p->obj->a);//可不可这样子访问
printf("obj-b=%d\n",p->obj->b);//可不可这样子访问
printf("obj-c=%.2lf\n",p->obj->c);//可不可这样子访问
return 0;
}