簡體   English   中英

指向指針成員Struct的指針

[英]Pointer to pointer member Struct

它是我正在處理的代碼的一部分。 當我嘗試將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;
}

您應該將其寫為ptr2 = Diagcb.end 因為Diagcd.end已經是一個指針,所以您不需要使用&來獲取地址。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM