Thread: returning arrays of structures

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    1

    Angry returning arrays of structures

    Hello

    can anyone help,,,
    I need to return an array of structures from a function after I handle it and change it...
    so my function accepts the array of structures as an argument and I want to return it...

    please help ...

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    arrays are automatically passed by reference. Any changes you make to the array in the function will be reflected back to the calling function.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Open to suggestions Brighteyes's Avatar
    Join Date
    Mar 2003
    Posts
    204
    need to return an array of structures from a function after I handle it and change it...
    so my function accepts the array of structures as an argument and I want to return it...
    You don't have to return it since an array parameter is converted to a pointer to the first element, any changes you make would be seen in the calling function anyway. But I've had plenty of times where I also returned the array for notational convenience, so you'd do it like this
    Code:
    struct T *f(struct T *t)
    {
        /* ... */
        return t;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 05-09-2009, 11:06 AM
  2. problem with arrays and structures
    By gell10 in forum C++ Programming
    Replies: 7
    Last Post: 11-03-2003, 12:02 AM
  3. Functions returning char arrays
    By turmoil in forum C Programming
    Replies: 3
    Last Post: 05-27-2003, 01:43 AM
  4. Returning Arrays
    By mr_spanky202 in forum C Programming
    Replies: 2
    Last Post: 04-06-2003, 02:57 PM