select elements from array C++

#include <iostream>

int main() {
    const int size = 5;
    int arr[size] = {1, 2, 3, 4, 5};
    int selected[size];

    // Select elements from the array based on a condition (e.g., even numbers)
    int selectedCount = 0;
    for (int i = 0; i < size; ++i) {
        if (arr[i] % 2 == 0) {
            selected[selectedCount] = arr[i];
            ++selectedCount;
        }
    }

    // Display the selected elements
    std::cout << "Selected elements: ";
    for (int i = 0; i < selectedCount; ++i) {
        std::cout << selected[i] << " ";
    }

    return 0;
}