Thread: How to write a function which returns a structure

  1. #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?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    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.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    26
    Code:
    typedef struct
    {
     int a;
    } STR;
    
    STR Func()
    {
     STR str;
     
     str.a = 5;
     return(str);
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

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

Tags for this Thread