Quantcast
Channel: Why do arrays in C decay to pointers? - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Why do arrays in C decay to pointers?

$
0
0

[This is a question inspired by a recent discussion elsewhere, and I'll provide an answer right with it.]

I was wondering about the odd C phenomenon of arrays "decaying" to pointers, e.g. when used as function arguments. That just seems so unsafe. It is also inconvenient to pass the length explicitly with it. And I can pass the other type of aggregate -- structs -- perfectly well by value; structs do not decay.

What is the rationale behind this design decision? How does it integrate with the language? Why is there a difference to structs?


Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images