CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2006
    Posts
    23

    Passing data between functions and main

    If I have declared variables in another function such as main, how do I access them in another function? (Instructor does not allow global variables)

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Passing data between functions and main

    100 bottles of beer on the wall, 100 bottles of beer, take one down pass it around, 99 bottles of beer on the wall....
    Code:
    void f(int& x) {
    	// ...
    }
    
    int main() {
    	int x = 0;
    	f(x);
    }
    though here I'm taking your "access them in another function" rather literally by passing by reference.

  3. #3
    Join Date
    Feb 2005
    Location
    "The Capital"
    Posts
    5,306

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured