Thread: Returning Arrays?

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    4

    Returning Arrays?

    Is it possible to return an array, or more then one variable from a function?

    Thanks,
    Nathan

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Is it possible to return an array, or more then one variable from a function?
    No. However, you can return a pointer to an array (but note that the array cannot be local to the function) or you can return a struct that consists of multiple values.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    95% of the cases when "you want to return an array", what should REALLY happen is that you pass an array INTO the function, and use the passed in array to fill in the data.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multidimensional arrays returning.
    By eXeCuTeR in forum C Programming
    Replies: 33
    Last Post: 07-01-2008, 12:27 PM
  2. Passing & Returning Arrays
    By jeffdavis_99 in forum C++ Programming
    Replies: 10
    Last Post: 04-02-2005, 06:44 PM
  3. Returning arrays from a function.
    By Jaken Veina in forum C Programming
    Replies: 14
    Last Post: 03-21-2005, 06:07 PM
  4. Functions returning char arrays
    By turmoil in forum C Programming
    Replies: 3
    Last Post: 05-27-2003, 01:43 AM
  5. Returning Entire Arrays
    By luckygold6 in forum C++ Programming
    Replies: 8
    Last Post: 03-15-2003, 06:54 AM