Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int* createInt()
- {
- int* ptr{ nullptr };
- ptr = new int{42};
- std::cout << "ptr = " << ptr << " *ptr = " << *ptr << '\n';
- *ptr = 38;
- std::cout << "ptr = " << ptr << " *ptr = " << *ptr << '\n';
- return ptr;
- }
- int main()
- {
- //int num{ 33 };
- int* pointToInt{ nullptr };
- pointToInt = createInt();
- std::cout << "pointToInt = " << pointToInt << " *pointToInt = " << *pointToInt << '\n';
- ++pointToInt;
- std::cout << "pointToInt = " << pointToInt << " *pointToInt = " << *pointToInt << '\n';
- // *pointToInt = 7777;
- std::cout << "pointToInt = " << pointToInt << " *pointToInt = " << *pointToInt << '\n';
- --pointToInt;
- std::cout << "pointToInt = " << pointToInt << " *pointToInt = " << *pointToInt << '\n';
- delete pointToInt;
- int arrSize{ 5 };
- //std::cin >> arrSize;
- //int arr[arrSize]{ 11,22,33,44,55 };
- //pointToInt = arr;
- //pointToInt = new int{ 11 };
- //pointToInt = new int[arrSize]{1,2,3,4,5};
- *pointToInt = 66;
- //for (int i{ 0 }; i < arrSize; ++i)
- //{
- // std::cout << "pointToInt = " << (pointToInt + i) << " *pointToInt = " << *(pointToInt + i) << '\n';
- //}
- delete pointToInt;
- return 0;
- }
Add Comment
Please, Sign In to add comment