[英]What does this pointer to pointer in a struct mean?
所以給了我一個結構:
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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.