Results 1 to 3 of 3

Thread: passing structure as an arguement to function

  1. #1
    Join Date
    Jun 2006
    Posts
    17

    Default passing structure as an arguement to function

    hey can any body tell me how to pass entire structure to a function ....if i donot want the function to return a value (void type function) how can i define and declare it.

  2. #2
    Join Date
    Jun 2006
    Posts
    17

    Default

    the query is both for c as well as c++

  3. #3
    Join Date
    Mar 2005
    Posts
    6

    Default

    u have to declare and initialise your struct first (in the main or where ever u wish)

    int main()
    {
    //declare your struct
    struct my_type{
    int num;
    char letter;
    }

    //put value to your struct
    struct my_type my_var{1,'c'};

    // here is how u parse it to a function
    my_function(my_var);
    }

    //this is your fucntion prototype
    void my_function(struct my_type myvar)
    {
    //..... do something.....
    }

    note: the above is for standard c though

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •