Advertisement
ArtisOracle

Untitled

Oct 22nd, 2012
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. int function(int z) // z is a parameter to the function 'function'
  2. {
  3.     int x, y;   // x, y are local variables to the function 'function'
  4.  
  5.     x = y = 10;
  6.     z = x + y;
  7.     return z;   // returns the VALUE of z only.
  8. }  
  9. // x, y, and z no longer exist. They're gone. Only the VALUE of z is returned to the caller. z itself is destroyed.
  10.  
  11. int function2(int a)    // a is a parameter to the function 'function2'
  12. {
  13.     int x, y;   // x, y are local variables to the function 'function2'. They are NOT, I repeat, NOT the same x and y as in function2. These variables are now ENTIRELY DIFFERENT EVEN IF THEY HAVE THE SAME NAME, because they are in a different set of { }s.
  14.     x = y = 10;
  15.     a = x + y;
  16.     return a;   // returns the VALUE of a only.
  17. }  
  18. // a, x, and y no longer exist to us anymore. They're gone. Only the VALUE of a is returned to the caller. a itself is destroyed.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement