我正在学习C语言,我对2D数组指针感到困惑。
我有以下声明
int a[3][5];
int *b[3][3];
int (*c)[3][5];
int *(d[3][5]);
int (*e[3])[5];
有人能帮我澄清一下吗
如果有有效的声明
a,b,c,d,e的大小(假设在64位机器上,地址id为8字节)
他们指的是
如何访问2D数组中的元素
我对指针在2D array.....and中的用法完全感到困惑,我猜其中一些是equivalent...but,有些可能不是很好的实践
我对以下两种方法感到困惑:
char var[3][15] = {"Hello_world!", "good", "bad"}; // as known this is for an 2D array.
char *var[3] = {"Hello_world!", "good", "bad"}; // and this I think also 2D array, but how.
他们之间有什么区别?
,什么情况可以使用?
我总是感到困惑,为什么Java中的2D数组对声明行的大小有严格的要求,而不是列的大小,这进一步混淆了3D和4D数组。
// Invalid, 2D array with no row and no column?
int[][] arr = new int[][];
// Valid, 2D array of size 2X3
int[][] arr = new int[2][3];
// Valid, column size is not specified, size of 2D array?
int[][] arr = new int[2][];
// Valid, column siz
当我们创建一个2d数组时,比如int[][] a = new int[2][3],为什么生成的2d数组由一个包含3个元素的整数数组的两个元素数组组成,而不是相反。我感到困惑的原因是,当我们做数组时,我们做datatype[],所以当我们做int2时,为什么不把三个int2数组放到一个有三个点的数组中(从3开始)。
我还不太擅长C语言,所以我有一些问题。
我有两个下面的结构:
typedef struct line_elems line;
typedef struct cache_handler *cache;
struct line_elems { // we don't care about valid/block bits in our simulator
int tag;
int freq; // for LRU principle
};
struct cache_handler {
int hit;
int miss;
int evict;
line **li
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int ar[2][2] = {1,2,3,4};
int **p= NULL , i=0, j=0;
p = ar; //compiler error. Confused ! Do i need to assign &a or anything.
puts("OUT: ");
for(i = 0; i < 2; i++)
{
for(j
我对C++程序中的这一行感到困惑。程序的思想是检查4x4数组是否对称。代码的这一部分声明了一个2D数组,我不明白。
int** array = new int*[n];
虽然,还有另一个类似的问题,但我得到的是关于单个指针的问题。
int *array = new int[n];
我不明白这个双指针。请解释一下。
下面这段简单代码在Matlab中的pythonic实现是等价的。
Matlab:
B = 2D array of integers as indices [1...100]
A = 2D array of numbers: [10x10]
A[B] = 0
其工作得很好,例如对于B[i]=42,它找到要设置的列5的位置2。在Python中,它会导致错误: out of bound is logical。然而,为了将上面的Matlab代码转换成Python,我们正在寻找Python的方法。还请考虑更高维度的问题,例如:
B = 2D array of integers as indices [1
我们在生产环境中遇到了奇怪的bug,我们既不能调试也不能注入日志代码。我试图弄清楚这一点,但跟踪堆栈跟踪让我感到困惑。
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.Collections.ArrayList.Add(Object value)
at ...
Add方法应仅引发NotSupportedException。
我不知道这是怎么回事。你是?