指向指针成员Struct

时间:2018-09-26 10:10:32

标签: c

它是我正在处理的代码的一部分。当我尝试将Diagcb.end分配给ptr2时,返回了错误。

我尝试将其写为:

ptr2 = &Diagcb.end;
ptr2 = &diagcb->end;

,但返回相同的错误。

typedef struct reportType {
    int a;
    int b;
    int c;
    int* ptr;
} reportType;

typedef struct cb {
    reportType* start;
    reportType* end;
    reportType arr[10];
}cb;
int fun (reportType* report);
main()
{
    cb Diagcb;
    reportType report;
    report.a = 0;
    report.b = 1;
    report.c = 2;
    report.ptr = NULL;
    reportType* ptr2;
    ptr2 = cb.end;
}

1 个答案:

答案 0 :(得分:0)

您应将其写为ptr2 = Diagcb.end。因为Diagcd.end已经是一个指针,所以您不需要使用&来获取地址。