Say i have 2 function, a and main. Function main wants to access a value used internally in function a without returning the value. Is there some simple way to do this? I'm pretty sure I know the correct syntax if I made them both member functions in a class. However, I think there should also be a more elegant solution using just pointers without the member functions.
A quick example I just made up in 5 secs to help illustrate my dilemna:
int a (int y, int z)
{
int x = y + z;
return y; // not allowed to return x so I just chose a dummy number
}
int main()
{
cout << int a(1,2);
cout << x; // where x is supposed to be the x in function a
// x is intentionaly currently uninitialized in the main function
}
obviously, returning x would be the easy solution to this problem , but I think i'm expressly forbidden from doing that
I do believe that x can be RETURNED from the a function. I know that you cannot access variables declared in function a in function main. Look up local and global variables.