Is it possible to pass an array by value to a C++ function?
If it is, how would I do that?
If by array you mean raw array, then the answer is No. You cannot pass them by value either in C or C++.
Both the languages provide a workaround, where you can wrap a struct around that array and pass its object. Example:
struct MyArray { int a[100]; };
...
struct MyArray obj; // `obj.a[]` is the array of your interest
foo(obj); // you have passed the `a[]` by value
In C++, such structs are readily available in form of std::vector and std::array.
Definitely:
void foo(std::array<int, 42> x);
42.std::array is not an array.Yes, you can. You can implement it by using a pointer as the argument, but in the function body, you can use the copy mothord (the exact name I can't remember) to copy it.
std::vector or std::array in C++.