c++指向动态矩阵中行的指针

标签 c++ pointers dynamic

我在以这种方式分配内存创建的类中有一个动态矩阵:

int **m;   //this in the member head pointer


void allocate_mem(int ***ptr, unsigned r, unsigned c){
    *ptr = new int *[r];
    (*ptr)[0] = new int[r*c];
    for(unsigned i = 1; i < r; i++)
        (*ptr)[i] = (*ptr)[0] + i*c;
}

如何调用指向行的指针?我的意思是,m是指向指针数组的指针,*m是指向第一行的指针,但我不知道如何调用指向另一行的指针

最佳答案

*m 确实是指向索引为 0 的行的指针,但是 *m 等同于 m[0]。所以对于其他索引使用 m[index]

关于c++指向动态矩阵中行的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21366301/

相关文章:

c++ - 是否有(更)合理的方法来确定 ostream 所针对的终端的宽度?

c++ - dyld : lazy symbol binding failed: Symbol not found. 预期在:平面命名空间

c - 4位十进制到16位二进制转换码

javascript - 动态加载外部 javascript 并将其绑定(bind)到特定的 DOM 元素或命名空间

javascript - iframe contentWindow 在缩短 document.domain 后抛出拒绝访问错误

c++ - Lambda 表达式偷偷捕获 `this`

c++ - 如何在不更改原始数组的情况下对指向结构的指针数组进行排序?

c++ - 错误 : Iso c++ forbids comparison between pointer and integer [c++]

c - 在C编程中将元素插入到动态字符数组中

c++ - UUID生成器问题