24 lines
417 B
C
24 lines
417 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
// 结构体存在堆区,结构体的成员也存在堆区
|
|
struct POS
|
|
{
|
|
int *x;
|
|
int *y;
|
|
};
|
|
|
|
int main()
|
|
{
|
|
struct POS *p1 = malloc(sizeof(struct POS));
|
|
p1->x = (int *)malloc(sizeof(int));
|
|
p1->y = (int *)malloc(sizeof(int));
|
|
|
|
*(p1->x) = 20;
|
|
*(p1->y) = 30;
|
|
|
|
printf("point1 x=%d, y=%d\n", *(p1->x), *((*p1).y));
|
|
|
|
return 0;
|
|
} |