Question On arrays in functions

closed account (NCRLwA7f)
Hello, working with some functions today, I ran into a few problems and found out that I don't really understand a few things with arrays or dynamic arrays for that matter.

maybe someone can give me a few examples or tell me how each instance of using an array in a function works. I know that arrays are passed by reference and don't get copied when getting passed to functions.


1
2
3
4
5
6
7
 
void Foo(int myArray[]);

void Doo(int &myArray);

void Woo(int *myArray)


what is the difference with the 3 above?
Woo and Foo are two ways of saying exactly the same thing. Even if you add a number in the brackets, it's basically just ignored. When you pass an array, the array is received as a pointer (when an array name is used in most contexts it becomes a pointer; one exception is sizeof).

Doo is unworkable. It's a reference to an int, which is not exactly like a pointer. In particular you can't use it like an array, i.e., you can't go a[0] since that's a form of dereferencing and a reference is automatically dereferenced on use.
Topic archived. No new replies allowed.