August 2001
Beginner
482 pages
10h 52m
English
The arguments passed in to the function are local to the function. Changes made to the arguments do not affect the values in the calling function. This is known as passing by value, which means a local copy of each argument is made in the function. These local copies are treated just as any other local variables. Listing 5.4 illustrates this point.
0: // Listing 5.4 - demonstrates passing by value 1: #include <iostream> 2: 3: void swap(int x, int y); 4: 5: int main() 6: { 7: int x = 5, y = 10; 8: std::cout << "Main. Before swap, x: " << x 9: << " y: " << y << "\n"; 10: swap(x,y); 11: std::cout << "Main. After swap, x: " << x 12: << " y: " << y << "\n"; 13: return 0; 14: ... |
Read now
Unlock full access