Advertisement
avr39ripe

PV024arr2DSimpleExample

Dec 2nd, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <iostream>
  2.  
  3.  
  4. int* createInt()
  5. {
  6.     int* ptr{ nullptr };
  7.     ptr = new int{42};
  8.    
  9.     std::cout << "ptr = " << ptr << " *ptr = " << *ptr << '\n';
  10.  
  11.     *ptr = 38;
  12.  
  13.     std::cout << "ptr = " << ptr << " *ptr = " << *ptr << '\n';
  14.  
  15.     return ptr;
  16. }
  17.  
  18.  
  19. int main()
  20. {
  21.     int num{ 33 };
  22.     int* ptrInt{ nullptr };
  23.     bool* ptrBool{ nullptr };
  24.     float* ptrFloat{ nullptr };
  25.     char* ptrChar{ nullptr };
  26.  
  27.  
  28.     ptrInt = new int{ 33 };
  29.     ptrBool = new bool[3]{ true,false,true };
  30.     ptrFloat = new float{ 42.1 };
  31.     ptrChar = new char[10]{ 'H','e','l','l','o','!' };
  32.  
  33.     //arr[i] <=> *(arr+i)
  34.  
  35.     ptrBool[1] = true;
  36.     *(ptrBool + 1) = true;
  37.     *ptrInt = 44;
  38.     ptrInt[0] = 44;
  39.  
  40.     delete ptrInt;
  41.     delete[] ptrBool;
  42.     delete ptrFloat;
  43.     delete[] ptrChar;
  44.  
  45.     ptrInt = &num;
  46.     //delete ptrInt;
  47.  
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement