|
|
发表于 2021-5-17 12:33:07
|
显示全部楼层
本楼为最佳答案
//这个*p3应该是个结构体指针吧,那么我怎么打印这个值呢 printf("%p\n",*p3);这个返回的好像是(nil),跟乱码了一样,我该怎么输出*p3的内容或者地址,就是我不知道怎么用这个*p3
是输出p3这个变量的地址还是输出p3指向的那个对象的地址?
- #include <stdio.h>
- #include <stdlib.h>
- typedef struct {
- int x, y;
- } point_t;
- point_t test1(point_t point) {
- return (point_t){point.x + 1, point.y + 1};
- }
- void test2(point_t *point) {
- point->x = 0;
- point->y = 0;
- }
- point_t *test3(void) {
- point_t *temp = malloc(sizeof(*temp));
- temp->x = 0;
- temp->y = 0;
- return temp;
- }
- int main(void) {
- point_t p1 = {0, 0};
- point_t p2 = test1(p1);
- test2(&p2);
- point_t *p3 = test3();
- printf("%p\n", &p3);
- printf("%p\n", p3);
- printf("%d, %d\n", p3->x, p3->y);
- free(p3);
- return 0;
- }
复制代码 |
|