Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- void printArr(int arr[], int arrSize)
- {
- for (int i{ 0 }; i < arrSize; ++i)
- {
- std::cout << arr[i] << ' ';
- }
- std::cout << '\n';
- }
- void printArr(int arr[], int idxBegin, int idxEnd)
- {
- for (int i{ idxBegin }; i < idxEnd; ++i)
- {
- std::cout << arr[i] << ' ';
- }
- std::cout << '\n';
- }
- void printArr(int* begin, int* end)
- {
- while (begin != end)
- {
- std::cout << *begin++ << ' ';
- }
- std::cout << '\n';
- }
- void fillArr(int* begin, int* end)
- {
- while (begin != end)
- {
- *begin++ = rand()%10;
- }
- std::cout << '\n';
- }
- int main()
- {
- const int arrSize{ 10 };
- int arr[arrSize]{ 1,2,3,4,5,6,7,8,9,10 };
- int* ptr{ arr + 4 }; // 100
- int* begin{ arr };
- int* end{ arr + arrSize };
- printArr(arr, 3, 8);
- printArr(arr + 3, arr + 8);
- fillArr(arr + 3, arr + arrSize - 3);
- printArr(arr, arr + arrSize);
- int num{ 42 };
- const int answer{ 42 };
- const int badAnswer{ -15 };
- int* ptrI{ &num };
- const int* ptrIC{ &num };
- int* const beginArr{ arr };
- const int* const zhest{ arr };
- int* ptr; //simple pointer pointer - rw *pointer - rw
- const int* ptrC; //pointer to constant pointer - rw *pointer - ro
- int* const cPtr{}; //constant pointer pointer - ro *pointer - rw
- const int* const cPtrC{}; //constant pointer to constant pointer - ro *pointer - ro
- int* point{ nullptr };
- point = # // single variable
- point = arr; // array begin, multipe variables
- std::cout << *ptrIC << '\n';
- //*ptrI = 100500;
- ptrIC = #
- *ptrIC = 100500;
- std::cout << *ptrIC << '\n';
- //int num{42}; //4
- //int num1{ 33 };
- //float val{ 42 }; // 4
- //bool flag{}; // 1
- //uint16_t word{ 1005 }; // 2
- //double temp{ 36.675 };
- //std::cout << "num is living at " << *(&num) << " address\n";
- //std::cout << "val is living at " << *(&val) << " address\n";
- //std::cout << "flag is living at " << *(&flag) << " address\n";
- ////int address{ (int)&num };
- ////std::cout << " address = " << address << '\n';
- ////void fun(int par);
- ////void fun(int* par);
- ////fun(0);
- ////fun(NULL);
- ////fun(nullptr);
- ////nullptr_t
- //// nullptr
- //int* ptrNum{nullptr}; //4
- //bool isNull{ nullptr };
- //std::cout << "In ptrNum is address: "<< ptrNum << '\n';
- //std::cout << std::boolalpha << isNull << '\n';
- //
- //{
- // int shortLifeVar{ 1111 };
- // ptrNum = &shortLifeVar;
- // std::cout << "Inside block *ptrNum = " << *ptrNum << '\n';
- //}
- //std::cout << "Outside block *ptrNum = " << *ptrNum << '\n';
- //if (ptrNum)
- //{
- // std::cout << *ptrNum << '\n';
- //}
- //else
- //{
- // std::cout << "nullptr detected! cannot dereference!!\n";
- //}
- //[100][104][108][112][116][120][124][128][132][136]
- // 5
- //100 + 5 * sizeof(int)
- //100 + 5 * 4
- //100 + 20 -> 120
- //ptr = ptr + 2; // 100 + 2 * sizeof(int) -> 100 + 2 * 4 -> 100 + 8 -> 108
- //
- //std::cout << *ptr << '\n';
- //--ptr; // 108 - 1 * sizeof(int) - > 108 - 4 -> 104
- //std::cout << *ptr << '\n';
- //std::cout << *(arr + 1) << " < = > " << ptr[1] << '\n';
- // *(ptr + i) < = > ptr[i]
- //for (int i{ 0 }; i < arrSize; ++i)
- //{
- // //std::cout << "Address: " << ptr + i << " = " << *(ptr + i) << '\n';
- // std::cout << *arr << " < = > " << ptr[0] << '\n';
- //}
- // *(ptr + i) < - > arr[i] < - > ptr[i]
- /*std::cout << std::boolalpha << (&arr[0] == &arr[0]) << '\n';
- std::cout << std::boolalpha << (&arr[0] <= &arr[0]) << '\n';*/
- //std::cout << arr << '\n';
- //while (begin != end)
- //{
- // std::cout << *begin++ << ' ';
- //}
- //std::cout << '\n';
- //int size;
- //std::cout << "Enter array size:\n";
- //std::cin >> size;
- //int* ptr{ new int[size] {1,2,3,4,5,6,7,8,9,10,11,12} };
- //begin = ptr;
- //end = ptr + size;
- //while (begin != end)
- //{
- // std::cout << *begin++ << ' ';
- //}
- //std::cout << '\n';
- //delete[] ptr;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement