C program working with dynamic array allocation