为什么在传递参数时使用const会给我一个警告?

ycs*_*hao 2 c pointers const function

为什么这段代码会给我一个警告:从不兼容的指针类型传递"test"的参数1?我知道这是关于char之前的const,但为什么呢?

void test(const int ** a)
{
}
int main()
{
    int a=0;
    int *b=&a;
    int **c=&b;
    test(c);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

caf*_*caf 5

你不能分配int **给a const int **,因为如果你这样做,后一个指针将允许你给一个int *变量一个const int对象的地址:

const int myconst = 10;
int *intptr;
const int **x = &intptr;    /* This is the implicit conversion that isn't allowed */
*x = &myconst;              /* Allowed because both *x and &myconst are const int * ... */
/* ... but now intptr points at myconst, and you could try to modify myconst through it */
Run Code Online (Sandbox Code Playgroud)