int * const * p和int ** constp p有什么区别

时间:2020-02-02 15:12:20

标签: pointers

#include <stdio.h>
    int main()
    {
        int i = 11;
        int *p = &i;
        foo(&p);
        printf("%d ", *p);
    }
    void foo(int *const *p)
    {
        int j = 10;
        *p = &j;
        printf("%d ", **p);
    }

FOO函数中的参数如何操作,int * const *和int ** const是同一件事?

1 个答案:

答案 0 :(得分:0)

这可以帮助您回答:Clockwise/Spiral Rule

然后下面是一些解释const和指针概念的示例:

int* - pointer to int
int const * - pointer to const int
int * const - const pointer to int
int const * const - const pointer to const int

现在第一个const可以位于类型的任意一侧,所以:

const int * == int const *
const int * const == int const * const

如果您想走得更远,可以执行以下操作:

int ** - pointer to pointer to int
int ** const - a const pointer to a pointer to an int //THIS IS YOUR CASE
int * const * - a pointer to a const pointer to an int //THIS IS YOUR CASE
int const ** - a pointer to a pointer to a const int
int * const * const - a const pointer to a const pointer to an int