In this case it is not necessary to put &
before the vector, let's analyze why, its function is void FPVazia(TipoPilha *Pilha)
note that what you ask for as a parameter is a pointer to a memory region, this which will be interpreted as a type, and when you call it you are passing the following, FPVazia(&Buckets[i]);
, and because this is wrong, here we fall into the definition of what is vector, a vector is a pointer to a memory region, which would be its first vector memory region, index 0.
So to make it easier for you to understand what you have done, another way of writing what you did is the following FPVazia(&(TipoPilha*)(Buckets + i));
, so you notice that what you are going through for your function is the memory address of your pointer and not the position of your vector, since a vector is already a pointer.
To fix this, just take this &
, being FPVazia(Buckets[i]);
or FPVazia((TipoPilha*)(Buckets + i));
, it is important to note that these two ways are equivalent, the only difference between them is that one omitted the pointer and the account position while the other does not.
The second way is done using pointer arithmetic, a pointer *
by itself is always interpreted as an integer in C, so to avoid any error always occurring when using pointer arithmetic remember to do the casting, so that the pointer is interpreted according to the type you are using, if the buckets variable is an integer vector you could leave only FPVazia(*(Buckets + i));
, but since it is not casting. Another important fact is that as previously stated you do Buckets[i]
or (TipoPilha*)(Buckets + i)
is the same thing, they are equivalent, because when you do Buckets[i]
what the computer interprets and does (TipoPilha*)(Buckets + i)
.
Another error that is explicit is that of for
, you start your i
in 10, and then increment it, only that its condition says that for i >= 0
you will do what is inside for
, but this condition will always be true soon your loop will be infinite, to fix it you just have to decrease your i
, or you start i
in 0, in condition put i < 10
, and hence increase i
.
Going straight to the answer, you can do the following:
for ( i = 10 ; i >= 0; i-- )
FPVazia(Buckets[i]);
or
for ( i = 10 ; i >= 0 ; i-- )
FPVazia((TipoPilha*)(Buckets + i));
or
for ( i = 0 ; i < 10; i++ )
FPVazia(Buckets[i]);
or
for ( i = 0 ; i < 10 ; i++ )
FPVazia((TipoPilha*)(Buckets + i));