|
5鱼币
问一下结构体,指针,数组,单链表他们都是地址么,为什么我经常感觉结构体和单链表,数组都是当做指针使用,大佬们可以帮忙举点例子解释一下么?
//这个*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;
- }
复制代码
|
最佳答案
查看完整内容
//这个*p3应该是个结构体指针吧,那么我怎么打印这个值呢 printf("%p\n",*p3);这个返回的好像是(nil),跟乱码了一样,我该怎么输出*p3的内容或者地址,就是我不知道怎么用这个*p3
是输出p3这个变量的地址还是输出p3指向的那个对象的地址?
|