自学内容网 自学内容网

c error: ‘*scan’ is a pointer; did you mean to use ‘->’?

此错误容易出现在**指针访问时,解决方法是使用()括起来,原因主要是类型不匹配。

#include <stdio.h>
#include <stdlib.h>

struct ac{
    int data;
    struct ac *next;
};

void address(struct ac *p)
{
    struct ac *next, **scan;
    struct ac pa;

    pa.data = 10;
    pa.next = &pa;

    next = p->next;
    scan = &p->next;

    printf("pa = %p\n", &pa);
    printf("pa.a = %p\n", &pa.data);
    printf("pa.next = %p\n\n", &pa.next);

    printf("next = %p\n", next);        // 一级指针指向地址 p->next
    printf("scan = %p\n", scan);        // 一级指针地址     &p->next
    printf("*scan = %p\n\n", *scan);    // 一级指针指向地址 p->next

    printf("p->next = %p\n", p->next);                  // 一级指针指向地址 p->next
    printf("p->next->next = %p\n", p->next->next);      // 一级指针指向地址 p->next->next
    printf("p->next->next->next = %p\n\n", p->next->next->next);      // 一级指针指向地址 p->next->next->next

    printf("&p->next->next = %p\n", &p->next->next);        // 一级指针地址
    printf("&(p->next)->next = %p\n", &(p->next)->next);    // 一级指针地址
    printf("&(p->next->next) = %p\n\n", &(p->next->next));  // 一级指针地址

    printf("(*scan)->next = %p\n\n", (*scan)->next);    // 一级指针指向地址 p->next->next
    //printf("*scan->next = %p\n", *scan->next);        // error: ‘*scan’ is a pointer; did you mean to use ‘->’?
    //printf("scan->next = %p\n", scan->next);          // error: ‘*scan’ is a pointer; did you mean to
use ‘->’?

    if ((*scan)->next == next) {
        printf("ditto\n\n");
    }

    p->next->next = &pa;
    printf("next = %p\n", next);        // 一级指针指向地址 p->next
    printf("scan = %p\n", scan);        // 一级指针地址     &p->next
    printf("*scan = %p\n", *scan);      // 一级指针指向地址 p->next
    printf("(*scan)->next = %p\n", (*scan)->next);      // 一级指针指向地址 p->next->next
    //printf("*scan->next = %p\n", *scan->next);        // error: ‘*scan’ is a pointer; did you mean to use ‘->’?
    printf("p->next->next = %p\n", p->next->next);      // 一级指针指向地址 p->next->next
}

int main()
{
    struct ac p;

    p.data = 10;
    p.next = &p;

    printf("p = %p\n", &p);
    printf("p.a = %p\n", &p.data);
    printf("p.next = %p\n\n", &p.next);
    address(&p);

    return 0;
}


原文地址:https://blog.csdn.net/xiaozhiwise/article/details/140530109

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!