C Programming · Interview question

Are arrays and pointers the same thing in C?

A strong answer

No, though decay makes them feel interchangeable. They differ concretely: sizeof on a true array gives the total storage; on a pointer it gives the pointer's own size. &arr has type "pointer to array" (int (*)[N]) whereas &p is int **. An array name is not an lvalue you can assign to (arr = something is illegal), but a pointer variable is reassignable. And an array contains its elements as storage, while a pointer merely holds an address that may point anywhere. The confusion arises because an array decays to a pointer in most expression contexts, but in declarations, sizeof, and &, the distinction is sharp and observable.

What a weak answer sounds like

You know the answer. Do you know what gets you dinged?

Pro breaks down the answer most candidates actually give to this question — and the specific reason an interviewer marks it down. It’s the difference between sounding correct and sounding senior, on all 472 questions.

From the lesson

Pointer Arithmetic & Arrays

Why arr[i] is literally *(arr + i), how pointer math scales by type size, and the array-to-pointer decay that loses your size the moment you call a function.

More Pointer Arithmetic & Arrays questions

Browse all 472 interview questions