Define an array instead of a pointer, and don't use malloc. I modified your program a little. You were creating a new array in dynamic memory every other loop iteration and not deleting them.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include<cstdio>
usingnamespace std;
int main(){
int a[11];
int top = 0;
for(int i=0;i<=20;i+=2)
a[top++] = i;
for(auto e : a)
printf("%d\n",e);
}