Is it possible to return an array from a function?

Discussion in 'C Programming' started by chming, Jan 14, 2005.

  1. chming

    chming Guest

    It is ok to return a struct variable from a function. How about an
    array of any type from a function?

    Because the array is allocated in the stack, it is no meaning to return
    it, which ever type it is. This array is the memory of stack.
    But for a struct, it is allocated
    chming, Jan 14, 2005
    #1
    1. Advertising

  2. On Fri, 14 Jan 2005 00:10:00 -0800, chming wrote:

    > It is ok to return a struct variable from a function. How about an
    > array of any type from a function?


    No, C doesn't support passing an array to or returning an array from a
    function. You cna of course return a structure with an array member.

    > Because the array is allocated in the stack,


    C has no concept of a stack, it is allocated as the implementation chooses.

    > it is no meaning to return
    > it, which ever type it is. This array is the memory of stack. But for a
    > struct, it is allocated


    If C supported returning arrays an implementation could probably use the
    same allocation mechanism that is uses for structures. However since it
    doesn't the issue doesn't arise.

    Lawrence
    Lawrence Kirby, Jan 14, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. chming
    Replies:
    2
    Views:
    267
    dandelion
    Jan 14, 2005
  2. Greenhorn
    Replies:
    15
    Views:
    784
    Keith Thompson
    Mar 6, 2005
  3. Replies:
    17
    Views:
    472
    Frederick Gotham
    Aug 25, 2006
  4. Replies:
    3
    Views:
    894
    Frederick Gotham
    Nov 30, 2006
  5. Davy
    Replies:
    9
    Views:
    1,377
Loading...

Share This Page