Is it bad practice to split a C array by simply using a pointer to the middle of it? Is it bad practice to split a C array by simply using a pointer to the middle of it? arrays arrays

Is it bad practice to split a C array by simply using a pointer to the middle of it?


I don't think it's bad practice if you know what you're doing. In some cases, you sacrifice readability for efficiency. It's probably more clear if you'd just create two more arrays, but if you have a firm grasp on arrays and pointers, why allocate extra memory?


Absolutely not! The whole point of programming in C is being able to do these neat pointer tricks!

Do note, however, that mergesort is not inplace so you will still need to malloc an auxiliary array. If you do the correct pointer tricks you can just malloc once and reuse it though.


It's just fine to use one array in such case (as merge sort). Calling malloc is unnecessary, unless the size of the array is too big for the stack.