Advertisement
avr39ripe

kirilPtrTrain

Jan 4th, 2021
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. void test1()
  4. {
  5.     double temp{ 36.6};
  6.     bool flag;
  7. }
  8.  
  9. int* test()
  10. {
  11.     return new int[5]{ 3,4,5,6,7 };
  12.  
  13. }
  14.  
  15. int main()
  16. {
  17.     int val{ 42 };
  18.     int arr[5]{ 1,2,3,4,5 };
  19.  
  20.     int* ptr{ nullptr };
  21.     std::cout << (val == *(&val)) << '\n';
  22.     ptr = &val;
  23.     *ptr = 567; // -> val = 567;
  24.  
  25.     ptr = (arr + 2);
  26.     ptr = &arr[2];
  27.     ptr = &*(arr + 2);
  28.     *ptr = 123;
  29.  
  30.     ptr = new int;
  31.     *ptr = 54;
  32.     std::cout << *ptr << '\n';
  33.     delete ptr;
  34.  
  35.     int arrSize{9};
  36.     ptr = new int[arrSize];
  37.     auto const delCopy{ ptr };
  38.     *(++ptr) = 56;
  39.     std::cout << *ptr << '\n';
  40.     delete[3] delCopy;
  41.  
  42.     ptr = test();
  43.  
  44.     *(ptr + 3) = 333;
  45.     std::cout << *(ptr+3) << '\n';
  46.  
  47.     delete[] ptr;
  48.  
  49.        
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement