gpt4 book ai didi

c++ - 指向 4 维数组的指针

转载 作者:行者123 更新时间:2023-11-28 06:08:53 25 4
gpt4 key购买 nike

<分区>

    int **z[DIM0] = {yr,ys};  ____210________218_______226________234________242________  |         |         |          |          |           |  |  218    | 226     |          |          |           |  |_________|_________|__________|__________|___________|_____       yr       *yr      xa[0]      xa[1]        xa[2]  ........                         ** yr

Hello,
I am trying to figure out logic of why type pointer to pointer int were used for array z elements type?

What happens when yr is assigned a type pointer to pointer int when array z is initialized. yr is and array of pointers to int. yr decays to pointer of int.
before array z is initialized.
But after z initializes yr is a pointer to pointer. Its no longer a pointer of type int due to decay? yr has and address what would address be after its converted to pointer to pointer of int as array z element. Could someone show memory diagram for yr, *yr, **yr?

after array z initialization after yr declaration

____200______208_____216_______________256________________|         |       |         |         |               ||         |   256 |         |         |      yr[0]    ||_________|_______|_________|_________|_______________|________|    yr      *yr     **yr                                                                       

confused I understand when you assign a type pointer to pointer to a pointer value. I understandhow memory is mapped. Confused because yr has and address before initialization.How is **yr created?

The following I follow.

int x = 5;
int *p = &x;
int **q = &p
___________240__________248________256_______|                    |            |          ||       248          |       256  |    5     ||___________________ |___________ |__________|         q                p             x
const int DIM = 2, DIM1 = 3, DIM2 = 4;
int xa[DIM2], xb[DIM2], xc[DIM2], xd[DIM2], xe[DIM2], xf[DIM2];
int *yr[DIM1] = {xa, xb, xc}, *ys[DIM1] = {xd, xe, xf};
**z[DIMO] = {yr, ys};

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com