Thread: returning int array from a function

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by rubu View Post
    So when returning the pointer to array.....how important is doing a malloc? is it really needed?
    If you want to return pointers to memory, then that memory has to exist after the function call ends. (The only other method to do that, other than malloc, is to maintain a static array and return a pointer to that. However, in that case, you only have one chunk of memory no matter how often you call the function -- that is, calling the function again will reuse the same memory, not get you more memory.)

  2. #2
    Registered User
    Join Date
    May 2011
    Posts
    10
    Quote Originally Posted by tabstop View Post
    If you want to return pointers to memory, then that memory has to exist after the function call ends. (The only other method to do that, other than malloc, is to maintain a static array and return a pointer to that. However, in that case, you only have one chunk of memory no matter how often you call the function -- that is, calling the function again will reuse the same memory, not get you more memory.)
    Got it....Thanks so much....again thanks so much for being patient...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. returning a 2D array from a function
    By sauwen in forum C Programming
    Replies: 5
    Last Post: 11-19-2010, 05:51 PM
  2. c++ -- returning an array from function
    By p4plus2 in forum C++ Programming
    Replies: 25
    Last Post: 08-18-2008, 01:48 PM
  3. Replies: 6
    Last Post: 11-09-2006, 03:28 AM
  4. returning an array from a function
    By BubbleBoy in forum C Programming
    Replies: 1
    Last Post: 02-20-2003, 12:41 PM
  5. returning a 2D array in a function
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 01-05-2002, 08:56 AM