In main (), define a pointer to the test structure:
struct test *testPtr;
To take the address of this pointer, use the & address-of operator:
&testPtr;
This returns the address of the pointer and is of type struct test **
You can then pass this into your func1 function, which makes the correct allocation (although casting malloc() usually considered bad practice - Am I taking the result of malloc? ). Other than that, func1() looks good ... line ...
*testobj = malloc(n*sizeof(struct test));
... right. *testobj your double pointer, which you do by doing &testPtr , and stores the new memory address in your pointer. You are also right when you look up your double pointer with (*testobj)[i] because [] has a higher priority than * which you need (as you did) to surround the dereferencing with brackets to make sure this will happen before you index.
Thus, when func1() returns a pointer to testPtr , it should now point to an array of n test structures that you have allocated, and they can be accessed using testPtr[i].a , etc.
EDIT: your for loop should become
for(i=0;i<n;i++) printf("%d %d", testobj[i].a, testobj[i].b);
Was your source loop supposed to give you compilation errors? testobj not a pointer in the source code, so dereferencing it should not be possible.
So, the final answer is in main() declare testobj as a pointer, and then accesses the elements of the array as testobj[n] :)
EDIT: As Eric pointed out, remove n=5; from func1() . I think you meant *n=5 , perhaps as some kind of debugging step ... You probably want to use n as an input to the function to indicate how many objects you want in your structured array. Either initialize n , or perhaps override func1() as
void func1(int n,struct test **testobj)