Advertisement
MeehoweCK

Untitled

May 20th, 2023
576
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void modyfikacja_liczby(int& liczba)        // przekazywanie argumentu funkcji poprzez referencję
  6. {
  7.     // funkcja, która pobiera argument jako referencję, pracuje na oryginalnej zmiennej, którą podaliśmy przy wywołaniu funkcji (kopia nie jest tworzona)
  8.     cout << liczba << endl;     // 2.   10
  9.     ++liczba;
  10.     cout << liczba << endl;     // 3.   11
  11. }
  12.  
  13. int main()
  14. {
  15.     int liczba = 10;
  16.     cout << liczba << endl;     // 1.   10
  17.     modyfikacja_liczby(liczba);
  18.     cout << liczba << endl;     // 4.   11
  19.     return 0;
  20. }
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement