# Thread: Confused with pointers and pass by reference

1. Originally Posted by AndiPersti
[code]
Basically *&i == i, because & and * cancel.
That was my point at the above post!

About tou example i think i got it.But let's check to be sure
Code:
#include <stdio.h>

int main(void)
{
int i, *ptr1, **ptr2, ***ptr3;

i = 10;
ptr1 = &i;
ptr2 = &ptr1;
ptr3 = &ptr2;

printf("%d\n", i == **ptr2);
printf("%d\n", i == **&ptr1);
printf("%d\n", *&i == ***ptr3);
printf("%d\n", &i == **&*&ptr2);

return 0;
}
ptr2 is a 'double' pointer so because of line 9 points to ptr1 and then points(finally) to i.So line 12 will output 1.
Line 13 * cancels & so we have i==*ptr1,of course true,so output 1.
Line 14 is equivalent to i==***ptr3 which is true,becaues ptr3 is a 'triple pointer' which first points to ptr2(line 9),then points to ptr1 and finally points to i(the value of i).So output 1.
Line 15 is equivalent to &i==*ptr2 .ptr2 is a double pointer,so it points first to ptr1 and finally at the value 1.So *ptr2 is going to give us the value of ptr1,which is the adress of i and so output is going to be again 1.
Correct?

2. Originally Posted by std10093
By writing
Code:
new_mysql_connection(&conn);
it is like 'killing' the pointer
Remember that & 'kills' the *
For me "killing" means to get rid of something (it's destructive).
When you add the & operator to a function argument, you don't get rid of the pointer but you construct a pointer to that argument (it's constructive).

That's why I think "killing" is misleading.

Bye, Andreas