return value by reference from a sub-function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anandkumar
    New Member
    • May 2010
    • 5

    #1

    return value by reference from a sub-function

    I have computed an array y[100] in a subfunction.

    The value of y needs to be referenced in the main function.

    Is it possible for me to pass the address of y[100] from the sub-function to the main function using the statement 'return(&y);' and reference y in main function using a pointer?

    Is there any similar way to access the variables by reference in a sub-function?
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    If you created y as a local variable of the sub-function then no because when the function exits the variable is deleted.

    You could declare the array in main and pass a pointer to it into the sub-function then the sub-function will work on the array in main.

    Comment

    • anandkumar
      New Member
      • May 2010
      • 5

      #3
      Hi Banfa,
      Thanks a lot for your suggestion.
      You have solved my problem.

      Thank you and regards :-)

      Comment

      Working...