What you are trying to do is assign a to point to the newly allocated memory, from what I gather. This won't work because a is an array, not a pointer. In order to achieve what you want you need to store and modify a pointer to an array. You can achieve your swap in two ways. For both, func1 will be:
void func1 () {
uint32_t t = 2;
uint32_t a[2] = {0x00000001,0x40000000};
uint32_t * b = a;
b = do_some_magic(&t);
work_with_modified(t,b);
}
uint32_t * do_some_magic(uint32_t *t){
*t++;
return malloc((*t) * sizeof(uint32_t));
}
or alternatively:
void func1 () {
uint32_t t = 2;
uint32_t a[2] = {0x00000001,0x40000000};
uint32_t * b = a;
do_some_magic(&t, &b);
work_with_modified(t,b);
}
void do_some_magic(uint32_t *t, uint32_t **b){
*t++;
*b = malloc((*t) * sizeof(uint32_t));
}
The second is closer to your original code. Of course error checking has been ignored here as with your original example. You also need to take note of the fact that do_some_magic has allocated memory on the heap. This memory needs to be freed later. If you call the do_some_magic multiple times, you need to free the memory pointed to by b before each subsequent call (except the first call where you used a automatically allocated array).
Finally, this and your original code are not really swapping arrays. The code simply allocates a new array in place of an old one. But I think this answers the essence of your question.