Passing variables through functions and structures?

This is a discussion on Passing variables through functions and structures? within the C++ Programming forums, part of the General Programming Boards category; Okay I had asked this question basically in an earlier thread but i do not think i was straght to ...

  1. #1
    Registered User dizz's Avatar
    Join Date
    Nov 2002
    Posts
    41

    Passing variables through functions and structures?

    Okay I had asked this question basically in an earlier thread but i do not think i was straght to the point. Anyways my second go at it.

    QUESTION:
    ~~~~~~~
    Is it possible to have a structure call a variable from it in a function edit it than call that variable into the main from the structure updated from the function?

    And if you can point me to a tutorial , lesson or quick example.

    Thank in advance.

  2. #2
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    359
    how can you call a variable? don't you mean make reference to a variable or along them lines? There are many ways that you can update variables in a structure going through a function. If the structure you are passing is very large, i would personally pass it through a pointer, thereby reducing the amount of data being put on the stack. However, if it's small you can pass it by reference.

    void whatevername(MyStrctureType *Structure);
    void whatevername(MyStrctureType &Structure);

    if your passing a single structure through a pointer user -> to access the members. An array you would use[]. By reference would be normal...

    Struct1.Num = 7; etc.
    Be a leader and not a follower.

  3. #3
    Registered User dizz's Avatar
    Join Date
    Nov 2002
    Posts
    41
    thanx that helped!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. questions about structures passing through functions
    By nareik9394 in forum C Programming
    Replies: 1
    Last Post: 03-18-2009, 06:19 PM
  2. Passing structures in C functions
    By trillianjedi in forum C Programming
    Replies: 11
    Last Post: 05-26-2008, 02:28 AM
  3. passing structures to functions
    By AmazingRando in forum C++ Programming
    Replies: 5
    Last Post: 09-05-2003, 11:22 AM
  4. passing array structures to functions
    By lukejack in forum C Programming
    Replies: 2
    Last Post: 04-08-2003, 02:17 PM
  5. Passing structures between functions
    By TankCDR in forum C++ Programming
    Replies: 2
    Last Post: 01-29-2002, 09:54 AM

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