Actual argument and Formal parameter:
| #include <iostream.h>
void getData(int &x, int &y); void main ()
void
getData(int &x, int &y)
|
#include <iostream.h>
void getData(int x, int y); void main ()
void
getData(int x, int y)
|
|
|
|
| Pass by reference:
num1 and x use the same box, num2 and y use the same box. |
Pass by value, num1 and x are different
boxes.
when main()calls getaDat(), the value of num1 is copied to x and the value of num2 is copied to y. But, when you finish executing getData(), and go back to main(), the value of x is not copied back to num1, similar to y and num2. |
|
In the getData(), you can not reference num1 and num2 . i.e. You can not use them in the getData(). That is, the scope of num1 and num2 is main() only. Similarly, the scope of x and y is getData() only. |
|