Guest User

Untitled

a guest
Feb 20th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. int mas[5] = {1, 2, 3, 8};
  2. const int *ptr1 = mas;
  3. const int (&ptr2)[5] = mas;
  4.  
  5. std::cout << sizeof ptr1 <<std::endl; // 4 или 8 - зависит от битности системы
  6. std::cout << sizeof *ptr1 <<std::endl; // 4 (скорее всего)
  7. std::cout << sizeof ptr2 <<std::endl; // 20
  8.  
  9. ptr1 = &mas[0];
  10.  
  11. ptr1 = &mas[1];
  12.  
  13. int i = 42;
  14. ptr1 = &i;
  15.  
  16. *ptr1 = 100500;
  17.  
  18. ptr2 = mas;
  19.  
  20. const int *ptr = mas;
  21.  
  22. const int (*ptr2)[5] = &mas;
  23.  
  24. const int &r = mas[1]; //Ссылка на второй элемент массива mas;
  25.  
  26. const int (&r2)[5] = mas;
  27.  
  28. int mas[5] = {1, 2, 3, 8};
  29.  
  30. const int *ptr = mas;
  31. int (*ptr2)[5] = &mas;
  32.  
  33. const int &r = mas[1];
  34. const int (&r2)[5] = mas;
  35.  
  36. cout << uintptr_t(ptr + 1) - uintptr_t(ptr) << " " << sizeof(int) << " " << sizeof(r) << endl;
  37. cout << uintptr_t(ptr2 + 1) - uintptr_t(ptr2) << " " << sizeof(mas) << " " << sizeof(r2) << endl;
  38. cout << sizeof(ptr) << " " << sizeof(*ptr) << " " << sizeof(ptr2) << " " << sizeof(*ptr2) << endl;
  39.  
  40. mas[1] = 42; (*ptr2)[2] = 24;
  41. cout << r << " " << r2[2] << endl;
  42. ptr = &mas[3];
  43. cout << *ptr << endl;
  44.  
  45. 4 4 4
  46. 20 20 20
  47. 8 4 8 20
  48. 42 24
  49. 8
Add Comment
Please, Sign In to add comment