小编Cyt*_*sis的帖子

C中使用2D数组的指针算法

我需要帮助理解如何在C中使用点算法来计算二维数组.我正在使用这个网站(http://www.geeksforgeeks.org/dynamically-allocate-2d-array-c/)作为参考(使用示例1) ,一个指针).

int numRows = 2;
int numColumns = 3;

double * arrayMatrix = malloc(numRows * numColumns * sizeof(double));

int row = 0;
int column = 0;

printf("\nPlease enter the elements of your augmented matrix:\n");
for(row = 0; row < numRows; row++)
{
    for(column = 0; column < numColumns; column++)
    {
        printf("A[%d][%d]:", row + 1, column + 1);
        scanf("%lf", &arrayElement);
        printf("\n");

        *(arrayMatrix + row * numColumns + column) = arrayElement;
        //arrayMatrix[row + numColumns + column] = arrayElement;
    } …
Run Code Online (Sandbox Code Playgroud)

c pointers pointer-arithmetic multidimensional-array

-1
推荐指数
1
解决办法
2837
查看次数