数组可以作为const指针调用吗?

时间:2010-02-26 12:16:16

标签: c arrays pointers

这是非常基本的...但如果有人知道这个,请帮帮我... 可以将数组作为const指针调用吗?

3 个答案:

答案 0 :(得分:5)

你的意思是“可以在需要const指针的地方使用数组”吗?在那种情况下,是的:

void f(const int* p)
{
    ...
}

int ar[10];
f(ar); // this works, array is essentially a pointer

答案 1 :(得分:3)

如果你指的是数组的地址,那么YES就是常数。

答案 2 :(得分:2)

是。当作为参数传递给函数时,数组总是衰减到指针。