1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
#include <iostream>
void PrintArray (const int* arr, const size_t count)
{
for (int i = 0; i < count; i++)
{
std::cout << arr[i] << ":";
}
std::cout << "\n";
}
void EraseOdd (int* arr, size_t & count)
{
int* src{ arr }, * dst{ arr }, i{ 0 };
while (src < arr + count)
{
*dst = *src;
src += 2;
dst++;
i++;
}
count = i;
}
int main ()
{
constexpr size_t ARRAYMAX{ 10 };
size_t count{ ARRAYMAX };
int testData[ARRAYMAX]{ 1,2,3,4,5,6,7,8,9,0 };
PrintArray (testData, count);
EraseOdd (testData, count);
PrintArray (testData, count);
return 0;
}
|