Array & Function questions

Hi! I'm not sure is this the right category for this kind of questions, but I guess I'll give it a try.. :D

Let's say I have declared an array (let it be a long long int array with 5000 elements) in my main function, then I call other function and pass the array as an argument to the function (How do I pass an array as an argument? xD I tried something but it kinda didn't work.. )- what happens when I do that? Can you explain that process.. Is the array copied or is function using former array.. If it is copied, does copying take a lot of time while working with arrays with lots of elements...
You may pass an array (by value) if it's wrapped in a struct in which case the array is copied.

Otherwise, you may pass a pointer to the array (again, the pointer is passed by value, but it just points to the original array -- none of the data is copied.) Typically with this method you also want to pass the size of the array as an argument to the function as the size of the array passed cannot be determined solely from the pointer.

You may not pass an array by reference.


If you see a function declared like:

void do_something( int array[], unsigned array_size)

it is equivalent to:

void do_something( int* array, unsigned array_size)
okay, thanks! :)
Topic archived. No new replies allowed.