I’m trying to send a pointer to function, but the pointer is part of an array of pointers
void func(A **pa)
{
return;
}
A *pa;
pa=(A*)malloc(2*sizeof(A));
So, the first item in the array pa[0] is easy to send (because it is the place the pointer points to)
func(&pa);
But now I get stuck, how can I send the second item? pa[1]
I tried something like func(&pa + 1*sizeof(A));
but it didn’t seem to work.
You are looking for
&pa[1]:By the way, I can’t tell if you mean to allocate an array of only two pointers, but if you are, the malloc is in error. It should be
What you are doing is allocating twice the size of an
A, which conceivably could be thousands of bytes long. That much space is not needed for a pointer to such an object.Also, in
C, one need not—and should not—cast the return type ofmalloc().