# Thread: I don't understand this code

1. ## I don't understand this code

I have the following code for binary heaps:
Code:
```#define Parent(x) ((x - 1) / 2)
#define Left(x) ((2 * x) + 1)
#define Right(x) ((2 * x) + 2)

#define MAX 10

void swapElem(int *a, int *b) {
int tmp;

tmp = *a;
*a = *b;
*b = tmp;
}

void insertHeap(Heap *h, int elem) {
if(h->size == MAX) return;

h->elem[h->size] = elem;
h->size++;

int idx = h->size - 1;

while(idx && h->elem[Parent(idx)] > h->elem[idx]) {
swapElem(h->elem + Parent(idx), h->elem + idx);

idx = Parent(idx);
}
}```
But I don't understand the line:
Code:
`swapElem(h->elem + Parent(idx), h->elem + idx);`
I mean, h->elem is an array, how come h->elem + idx (for instance), produce a number? I'm adding idx to h->elem but h->elem is not a value it's an array.

What does it mean?

2. Originally Posted by Nazgulled
I mean, h->elem is an array, how come h->elem + idx (for instance), produce a number?
It doesn't. It produces a pointer. A pointer is what the swap() function expects, so all is well.

If a is an array and i is an offset, then the expression a + i is equivalent to &a[i]. Does that make it clear?

3. Yes, but I think I'll change my code to the expression &a[i], I'm more comfortable with it and I already know what it means. The way I currently have, confuses me a bit.

Thank you.