Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- int& max(int& a, int& b)
- {
- return a > b ? a : b;
- }
- int& max(int* arrB, int* arrE)
- {
- int* const arr{ arrB };
- int maxIdx{ 0 };
- for (int i{0}; arrB != arrE; ++i, ++arrB)
- {
- if (*(arrB) > *(arr + maxIdx))
- {
- maxIdx = i;
- }
- }
- return *(arr + maxIdx);
- }
- int& testFunc()
- {
- int random{ 42};
- return random;
- }
- int* testFunc1()
- {
- int random1{ 33 };
- return &random1;
- }
- void calcArr(int* arrB, int* arrE, int& pos, int& neg, int& zero)
- {
- while (arrB != arrE)
- {
- if (*arrB > 0) { ++pos; }
- else if (*arrB < 0) { ++neg; }
- else { ++zero; }
- ++arrB;
- }
- }
- void calcArr(int* arrB, int arrSize, int& pos, int& neg, int& zero)
- {
- for (int i{0}; i < arrSize; ++i)
- {
- if (arrB[i] > 0) { ++pos; }
- else if (arrB[i] < 0) { ++neg; }
- else { ++zero; }
- }
- }
- void boom()
- {
- uint64_t bigArr[10000]{};
- std::cout << "Boom!\n";
- }
- void printArr(const int* begin, const int* const end)
- {
- while (begin != end)
- {
- std::cout << *begin++ << ' ';
- }
- std::cout << '\n';
- }
- void fillArr(int* begin, const int* const end, int val)
- {
- while (begin != end)
- {
- *begin++ = val;
- }
- }
- int main()
- {
- const int srcSize{ 10 };
- int arrSrc[srcSize]{ 1,2,3,4,5,6,7,8,9,10 };
- int testArr[srcSize]{ 1,3,6,2,7,8,9,11,4,7 };
- int calcTest[srcSize]{ 0,1,2,0,-1,-6,3,0,-7,3 };
- const int destSize{ 11 };
- int arrDest[destSize]{};
- int p{};
- int n{};
- int z{};
- calcArr(calcTest, calcTest + srcSize, p, n, z);
- std::cout << "Positive: " << p << "\nNegative: " << n << "\nZero: " << z << '\n';
- ////std::cout << testFunc() << '\n';
- //int* ptr{ testFunc1() };
- //std::cout << *ptr << '\n';
- ////boom();
- //std::cout << *ptr << '\n';
- //int x{ 10 };
- //int y{ 20 };
- //std::cout << max(testArr, testArr + 5) << '\n';
- //std::cout << max(testArr+5, testArr + srcSize) << '\n';
- //*(max(&x, &y)) += 10;
- /*max(x, y) += 10;
- std::cout << "x = " << x << " y = " << y << '\n';*/
- //int* const ptr{ arrSrc };
- //*(ptr + 4) = 55;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement