The catch lies here

for(int i=0; i<n; i++,ptr++)

If you see there is a ptr ++ and ptr is always a base pointer and so the amount of values that are incremented at\re size of base and so once it prints a and then b and so the output is 01010