[英]Size of a 2d array in C++
I am solving problems on online judge like Leetcode and I wonder if it' possible to get size of a 2d array given int**A.我正在解决像 Leetcode 这样的在线法官的问题,我想知道是否有可能在给定 int**A 的情况下获得二维数组的大小。 Consider the function,考虑 function,
int help(int** A){
int rows = sizeof(A)/sizeof(A[0]);
int columns = sizeof(A[0])/sizeof(A[0][0]);
}
But I am not getting the correct values of rows and columns.但我没有得到正确的行和列值。 Is there a way to get sizes of a 2d array if I only have int** A. Same question for char** A. I know that the question is poorly framed but I am a beginner in C.如果我只有 int ** A 是否有办法获得二维数组的大小。对于 char ** A 也有同样的问题。我知道这个问题的框架很差,但我是 C 的初学者。 Thank you.谢谢你。
There's nothing in the allocated memory that indicates where it starts and ends.分配的 memory 中没有任何内容指示它的开始和结束位置。 For 2D arrays, there's not even a guarantee the memory is contiguous.对于 2D arrays,甚至不能保证 memory 是连续的。
**A
does not contain any data about itself - all of the info about the array must be kept track of by the programmer. **A
不包含任何关于它自己的数据——关于数组的所有信息都必须由程序员跟踪。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.