Tranvick

Example3

Jan 7th, 2013
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. //Пример3.Указатели и ссылки:
  2. //сравнительный анализ
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. void inc1(int x) {
  8.     ++x;
  9. }
  10.  
  11. void inc2(int & x) {
  12.     ++x;
  13. }
  14.  
  15. void inc3(int * x) {
  16.     ++(*x);
  17. }
  18.  
  19. int main() {
  20.     int x = 10;
  21.     cout << x << " ";
  22.     inc1(x);
  23.     cout << x << " ";
  24.     inc2(x);
  25.     cout << x << " ";
  26.     inc3(&x);
  27.     cout << x << endl;
  28.     cout << x << " " << &x << " " << *&x << endl;
  29.     int & p = x;
  30.     p = 100;
  31.     cout << x << endl;
  32.     int * f = &x;
  33.     *f = 200;
  34.     cout << x << endl;
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment