Why can’t we pass arrays to function by value?

The origin is historical. The problem is that the rule “arrays decay into pointers, when passed to a function” is simple.

Copying arrays would be kind of complicated and not very clear, since the behavior would change for different parameters and different function declarations.

Note that you can still do an indirect pass by value:

struct A { int arr[2]; };
void func(struct A);

Leave a Comment