将多维数组转换为 C 中的指针
给定一个表示为 double[4][4] 的多维数组,目标是转换将其转换为与取矩阵逆的函数兼容的双指针。
问题:
尝试直接使用 (double**)startMatrix 转换数组没有得到想要的结果。
解决方案:
由于 double[4][4] 数组与 double 指针不兼容,需要一种替代方法。
创建 double *[4] 类型的临时索引数组,该数组指向原始数组中每行的开头:
<code class="c++">double *startRows[4] = { startMatrix[0], startMatrix[1], startMatrix[2], startMatrix[3] }; double *inverseRows[4] = { /* same thing here */ };</code>
将这些索引数组传递给改为函数:
<code class="c++">MatrixInversion(startRows, 4, inverseRows);</code>
反转完成后,结果将存储在原始 inverseMatrix 数组中。
以上是如何在 C 中将多维数组转换为指针以进行矩阵求逆?的详细内容。更多信息请关注PHP中文网其他相关文章!