该函数需要一个指向二维数组[4][5]的指针.实际上,我们可以提交一个指向一维数组[20]的指针.Ie源代码如下所示:
extern f (int a[4][5]);
int b[20];
void func (void)
{
f (b);
}
这是完美的工作代码(如果内部的数组b,我们将像他们在一个二维数组的布局)。不过,汇编将发出警告(由于类型不足):
$ gcc t.c -c
t.c: In function 'func':
t.c:7: warning: passing argument 1 of 'f' from incompatible poin
我正在写一段代码来处理二维char数组。
char *board[] = {"aa"};
我将数组传递给一个函数
search(board, row, col);
..........
bool search(char** boards, int row, int col)
{
// Inside the function, I want to modify the boards[x][y]
// from the board within x and y, x < row, y < col
// I get the s
我想在visual studio 2017 c中初始化一个大小可变的二维数组。它是一个具有整数维数的简单正方形。然而,我得到了下面的错误,缺少下标,并且不能分配一个固定大小为0的数组。
int dim = 10;
short square [dim][dim];
使用malloc不能像以前那样使用二维,这意味着其余的代码不再工作,在visual studio 2017中仍然使用具有可变大小的二维数组的最佳解决方案是什么?
int *arr = (int *)malloc(row * col * sizeof(int));
我现在正在学习c,我正在学习指针。我读过一些例子,我想出了以下几个例子:
#include <stdio.h>
int main ()
{
float balance[10][5];
float *p;
p = (float *) balance;
*(p + 16) = 200.0; //init the balance[3][1] with the value 200.0
printf("%f\n", balance[3][1]);
return 0;
我想知道是否有可能在C中创建一个具有不同线大小的二维数组。 我知道二维数组是存储其他数组的数组。但是如果数组的大小不同呢?就像这样( "T“是数组的可用位置) 0 1 2 3 4
0 T T
1 T T T T T
2 T T T
3 T T T T 如果可能的话,该怎么做呢?就像普通的二维数组一样?
我正在学习C语言,但在将二维数组的指针传递给另一个打印二维数组的函数时遇到了问题。任何帮助都将不胜感激。
int main( void ){
char array[50][50];
int SIZE;
...call function to fill array... this part works.
printarray( array, SIZE );
}
void printarray( char **array, int SIZE ){
int i;
int j;
for( j = 0; j < SIZE; j++ )
在一个小的C++示例中遇到了下面显示的代码:
int (*arr1)[ARRAY_SIZE];
int (*arr2)[ARRAY_SIZE];
int (*arr3)[ARRAY_SIZE];
然后在类的构造函数中:
ParallelMultiply::ParallelMultiply(int mat1[ARRAY_SIZE][ARRAY_SIZE],
int mat2[ARRAY_SIZE][ARRAY_SIZE],
int result_mat[ARRAY_SIZE][ARRAY_SIZE]):arr1(m
所以我在一些课堂讲稿中有下面的例子
void f(int **p){}
void g(int *p[]){}
void h(int p[2][3]){}
int main(){
int **a;
allocate_mem(a); // allocate memory for a
f(a); // OK!
g(a); // OK!
// h(a); // NOT OK
int b[2][3];
// f(b); // NOT OK
// g(b); // NOT OK
h(b); // OK!
return 0;
}
(没有任何进一步
我有一个二维数组。第一个维度有固定的大小,我动态地创建第二个维度。e.g
int **arr;
*arr=( int * ) malloc ( X * sizeof ( int )) // X is input from user
我想做的是创建第二个维度,并在它的末尾写入值。
例如,我使用以下命令为arr创建第二维
arr[0]=( int * ) malloc ( 2 * sizeof ( int ))
然后我想在这个第二维中写入值,但不知道索引。许多编程语言都有array.push方法,该方法在不知道数组的索引或长度的情况下将项推入数组的末尾。我如何在C中实现这样的结果?
我有一个二维数组,如下所示:
void getC(int **p)
{
*p = &c[0][0];
}
int c[10][10];
int *a;
getC(a);
a[0][0];
it says error: no match for 'operator[]' in `a[0][0];` what is the problem and how to fix it?