Mar 5, 2014 at 6:21pm UTC
I dont understand how this code works. How did they get the variable z and why does proc1 print twice?
using namespace std;
const int X = 3;
void Proc1 (int &Y)
Y = 6;
cout << "Inside Proc1, X:" << X << " Y:" << Y <<"\n";
int Proc2(int &Y,const int Z)
cout << "Inside Proc2,X: " << X << "Y: " << Y << "Z: " << Z << "\n";
C = Proc2 (A,B);
cout << "Finally,A: " << A << "B: " << B << "C: " << C << "\n";return(0);
Mar 5, 2014 at 6:26pm UTC
1) Please use code tags when posting code, to make it readable:
2) Z is defined as one of the arguments to Proc2:
3) Proc1 prints twice, because it's called twice:
I get the impression that you don't yet understand even the fundamentals of what a function is and how you call them. I strongly recommend going back to the chapter in your textbook on functions, and re-reading it.
Topic archived. No new replies allowed.
General C++ Programming
© cplusplus.com, 2000-2017 - All rights reserved -
Spotted an error? contact us