C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 03-01-2009, 03:21 PM   #1
Registered User
 
Join Date: Feb 2009
Location: Seattle
Posts: 39
How to write a function which returns a structure

What is the prototype and definition of a function which returns a structure?
MSF1981 is offline   Reply With Quote
Old 03-01-2009, 03:26 PM   #2
and the hat of vanishing
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,214
Same as any other kind of function which returns a value.

There's no new syntax, so try the obvious thing and see what happens.

Unless you're using some 30-year old fossil compiler, this capability has been officially part of C since 1989.
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Up to 8Mb PlusNet broadband from only £5.99 a month!
Salem is offline   Reply With Quote
Old 03-01-2009, 03:40 PM   #3
Registered User
 
Join Date: Jan 2009
Posts: 26
Code:
typedef struct
{
 int a;
} STR;

STR Func()
{
 STR str;
 
 str.a = 5;
 return(str);
}
baccardi is offline   Reply With Quote
Reply

Tags
function, return, struct, structure

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Polynomials and ADT's Emeighty C++ Programming 20 08-19-2008 08:32 AM
Screwy Linker Error - VC2005 Tonto C++ Programming 5 06-19-2007 02:39 PM
Game Pointer Trouble? Drahcir C Programming 8 02-04-2006 02:53 AM
Binary Search Trees Part III Prelude A Brief History of Cprogramming.com 16 10-02-2004 03:00 PM
qt help Unregistered Linux Programming 1 04-20-2002 09:51 AM


All times are GMT -6. The time now is 09:23 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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