Alcott Alcott - 1 year ago 98
C++ Question

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

Apparently, we can pass complex class instances to functions, but why can't we pass arrays to functions?

Answer Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download