3 Replies - 127 Views - Last Post: 30 July 2012 - 08:15 PM Rate Topic: -----

#1 IndiaJonathan  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 12
  • Joined: 27-July 12

How do I return an array in a func, I realize this requires pointers

Posted 30 July 2012 - 07:49 PM

Hello, I am trying to return an array, for example:
int main()
{
   string billy [] = {"falfkja", "2", "77", "40", "12071"};
    changethatstring(billy);
system("pause");
return 1;
}



string changethatstring(string arraystuff[]){
     arraystuff[1]="test";
       return arraystuff[];
       }


Is This A Good Question/Topic? 0
  • +

Replies To: How do I return an array in a func, I realize this requires pointers

#2 GWatt  Icon User is offline

  • member icon

Reputation: 257
  • View blog
  • Posts: 3,035
  • Joined: 01-December 05

Re: How do I return an array in a func, I realize this requires pointers

Posted 30 July 2012 - 07:59 PM

Since arrays in C/C++ are stored on the stack you can't return them, or the address of any local variable for that matter. However, since you are using C++ you can use vectors. Is there a reason you don't use a vector?
Was This Post Helpful? 1
  • +
  • -

#3 IndiaJonathan  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 12
  • Joined: 27-July 12

Re: How do I return an array in a func, I realize this requires pointers

Posted 30 July 2012 - 08:02 PM

The only reason is because I don't understand them yet, could you give me an example?

And not just an example, please give one with passing it through the functions.
Was This Post Helpful? -2
  • +
  • -

#4 jimblumberg  Icon User is online

  • member icon

Reputation: 3051
  • View blog
  • Posts: 9,291
  • Joined: 25-December 09

Re: How do I return an array in a func, I realize this requires pointers

Posted 30 July 2012 - 08:15 PM

I recommend that you Google std::vector, study the documentation for this class and try to implement your program. You may also want to study the links in my signature, they should help you understand functions.

Jim
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1