找到一个二维数组的尺寸用C指针 [英] Finding dimensions of a 2D array in C using pointers

查看:135
本文介绍了找到一个二维数组的尺寸用C指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我C语言创建一个二维数组如下:

I create a 2D array in C as follows:

int **arr;
arr = malloc(rows * sizeof(int *));

for (i = 0; i < rows; i++)
    arr[i] = malloc(cols * sizeof(int));

现在,我呼吁:

func(arr)

在功能 FUNC ,我怎么计算的行和列的尺寸是多少?

In the function func, how do I calculate the row and column dimensions?

推荐答案

您无法计算它 - 改编只是一个指针的指针,也没有更多与它相关联(与所有C数组)的信息。你必须通过尺寸为单独的参数。

You can't calculate it - arr is just a pointer to a pointer, there is no more information associated with it (as with all C arrays). You have to pass the dimensions as separate arguments.

这篇关于找到一个二维数组的尺寸用C指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆