gpt4 book ai didi

c - this pointer to pointer in a struct 是什么意思?

转载 作者:太空狗 更新时间:2023-10-29 17:24:59 25 4
gpt4 key购买 nike

所以我得到了一个结构:

struct Xxx
{
struct Yyy{...};
Yyy **yyys; // matrix of yyys
};

我对指向指针的指针与矩阵的关系感到困惑?

我如何初始化一个新的 Yyy 和一个新的 Xxx

最佳答案

一级指针指向一个指针数组,每个二级指针指向一个Yyy数组。

它们可以设置如下:

struct Yyy **makeMatrix(int rows, int cols)
{
int i;
struct Yyy **result = malloc(rows*sizeof(struct Yyy *));
for (i = 0; i < rows; i++) {
result[i] = malloc(cols*sizeof(struct Yyy));
}
return result;
}

关于c - this pointer to pointer in a struct 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35161362/

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