kiddo
kiddo

Reputation: 1626

Can an array be called as a const pointer?

this is very basic...but please help me if anybody know about this... Can an array be called as a const pointer?

Upvotes: 2

Views: 262

Answers (3)

Ashish Yadav
Ashish Yadav

Reputation: 1697

if you are referring to the array's address then YES it will be a constant.

Upvotes: 2

Paul R
Paul R

Reputation: 212969

Yes. An array always decays to a pointer when passed as a parameter to a function.

Upvotes: 2

Vlad
Vlad

Reputation: 35594

Do you mean "can array be used where a const pointer is expected"? In that case, yes:

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

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

Upvotes: 5

Related Questions