如何从C中的数组中获取值?

use*_*316 1 c arrays pointers

我有一个像这样的二维数组:

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?
Run Code Online (Sandbox Code Playgroud)

Car*_*rum 5

  1. 您正在使用C++编译器编译C程序.小心!

  2. 您需要cgetC函数上面定义(或提供前向声明).

  3. 你有一个函数以外的语句,这在C中是不允许的.用它包装int *a和后续行int main(void) { ... }

  4. 你需要一个&让你的getC()电话合法 - 你正在通过int *,但它期望int **:

    getC(&a);
    
    Run Code Online (Sandbox Code Playgroud)
  5. 声明a[0][0]没有效果,无论如何都是错的,因为a它只是一个int *; 你不能两次取消引用它.

您可能应该获得一本初学者C书并开始学习它.