Karan Kalra
Karan Kalra

Reputation: 413

Is int *a[5] an array of 5 pointers or a pointer pointing to an array of size 5?

int *a[5];

Is this an array of 5 pointers or a pointer pointing to an array of size 5?

Upvotes: 1

Views: 723

Answers (3)

elyashiv
elyashiv

Reputation: 3691

that's an array of pointers. that's because int * is a type, unlike the impression most people get that the type is int and the name is *a .

Upvotes: 0

pb2q
pb2q

Reputation: 59617

It's an array of 5 pointers to int.

You might find the right-left rule helpful.

Upvotes: 3

obataku
obataku

Reputation: 29646

For future reference, use cdecl.org.

Entering int *a[5], the output is...

declare a as array 5 of pointer to int

Thus, a is an array of 5 int *. :-)

Upvotes: 5

Related Questions