By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,778 Members | 1,890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,778 IT Pros & Developers. It's quick & easy.

Returning an array of elements

P: 93
Hi,
How can I return an array of elements from a function?

ex.


Expand|Select|Wrap|Line Numbers
  1. Function()
  2. {
  3.         int array[] = { values };
  4. }
  5.  
How do I return the array from the function? Do I have to pass an array to the function by reference from outside to get it done? Is that the only way?
Mar 19 '07 #1
Share this Question
Share on Google+
3 Replies


rickumali
P: 20
Expand|Select|Wrap|Line Numbers
  1. Function()
  2. {
  3.         int array[] = { values };
  4. }
  5.  
How do I return the array from the function? Do I have to pass an array to the function by reference from outside to get it done? Is that the only way?
You can definitely return the array (or at least a pointer to the array), but since this C/C++, I'm sure you'll have to allocate some space for it. (Sorry, but my C/C++ is hazy.) Good luck with this!
Mar 19 '07 #2

P: 93
Nope. I do not want to return a pointer to it. That wold mean that I have to allocate memory for the array. I want the array passed by value, if that can be done.
Mar 19 '07 #3

dmjpro
100+
P: 2,476
mind itttt!!!!!!!!!!!!!!!!!!!!!!!!!!1

The array never be passed by value .... it always passed by reference.
Mar 19 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.