C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 03-31-2003, 06:53 AM   #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 ...
manolo21 is offline   Reply With Quote
Old 03-31-2003, 07:18 AM   #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
Stoned_Coder is offline   Reply With Quote
Old 03-31-2003, 08:09 AM   #3
Open to suggestions
 
Brighteyes's Avatar
 
Join Date: Mar 2003
Posts: 204
Quote:
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;
}
Brighteyes is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Doubt regarding C structures and arrays. Quick suggestions please cyrux C Programming 3 05-09-2009 11:06 AM
problem with arrays and structures gell10 C++ Programming 7 11-03-2003 12:02 AM
Functions returning char arrays turmoil C Programming 3 05-27-2003 01:43 AM
Returning Arrays mr_spanky202 C Programming 2 04-06-2003 02:57 PM


All times are GMT -6. The time now is 02:06 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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