Calling a function that returns an array

This is a discussion on Calling a function that returns an array within the C Programming forums, part of the General Programming Boards category; Let's say I have a mian function that calls a subroutine. This subroutine returns an array. What is the best ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    196

    Calling a function that returns an array

    Let's say I have a mian function that calls a subroutine. This subroutine returns an array. What is the best way to go about doing this? Can I initailize the array in the subroutine? Should I have the subroutine return one element at a time, or is there a way I can have it return the entire array all at once? Would it best to make use of pointers? Any advice?

    thanks,
    thetinman

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You can't return arrays. You can at best, return a pointer to it, if it's static. You'll need to use dynamic memory allocation (malloc and friends).


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Calling an array into another in a function
    By kroms in forum C Programming
    Replies: 7
    Last Post: 02-28-2009, 08:07 PM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 06:05 PM
  4. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21