Passing Arrays as Parameters to a Function? HELP!

I have a question on a homework assignment that I would like to understand/answer better.

When an array is passed as an actual parameter to a function, what is really being passed into the function? Why are arrays passed this way?

I researched this topic on cplusplus and I do to some level understand how arrays are passed and to some level why that is. I answered this as......

Arrays are passed by reference or as formal parameters. Meaning their memory location in RAM is passed. Therefore, you do not need to include the ‘&’. Furthermore, c++ will not let us pass a block of values in memory but it will let us pass it's memory location.

I do not know if this is a good answer and i'm not asking for someone to give me the answer. But it would be great if someone could explain this topic more to me.

as far as i remember arrays are always passed as a reference to the beginning of the array, except you pass a single element of that array.
Last edited on
Arrays normally degrade into pointers to the first element of the array. These pointers and be added to and/or indexed to access other elements in the array. It is possible to pass an actual non-degraded array by reference, but it requires knowing the size of the array in advance and the syntax is ugly. It also only works with actual arrays, not pointer-style arrays.

Arrays are NOT passed by reference unless you explicitly use special syntax to do so.
Topic archived. No new replies allowed.