# still confused about pointer and binary search tree...

• 02-28-2010
winggx
still confused about pointer and binary search tree...
so, what is the relationship between a pointer and a tree?
is it true that every element in a tree must be a pointer?
and what' is the point of using a pointer...? i really get confused...
and i need some help with udnerstanding pointer too...

what is the difference between the following..?
int *a = 123;

and

int *a=(malloc(sizeof(int));
*a = 123;
• 02-28-2010
nonpuz
Quote:

Originally Posted by winggx
what is the difference between the following..?
int *a = 123;

and

int *a=(malloc(sizeof(int));
*a = 123;

The difference is that int * a = 123; is trying to assign the address "123" to the pointer to int a. And pretty much invalid.

The second statement is allocating the size of an int and assigning that memory to the pointer to int a, then assigning the memory pointed to by a (referenced by *a) the number 123.
• 02-28-2010
Quote:

Originally Posted by winggx
so, what is the relationship between a pointer and a tree?

what is the difference between the following..?
int *a = 123;

and

This is an error - missing a )
Quote:

int *a=(malloc(sizeof(int));
*a = 123;
Pointers make up the "branches" of a tree. They give it an organized structure. If you want to get to the "fruit", you have to go "monkey style" along the branches.

What is the difference when you print out their values? Don't be restrained from testing these things out for yourself - that's an excellent way to learn them, so you remember.
• 02-28-2010
winggx
ic...thx for the help...but i got another question...
what does it mean when there are two "*" when declaring a pointer?

eg
Code:

```int main() {   int j = 2666, k = 136;   int *pti = &j;   int **ptpti = &pti;   *pti = 241;   *ptpti = &k;   j = **ptpti;   **ptpti = 251;   pti = malloc(sizeof(int));   *pti = j;   k = **ptpti;    *pti = 123;   j = **ptpti;   *ptpti = &j;   printf(%d %d\n, j, k); }```
• 02-28-2010
thillai_selvan
** means pointer to pointer.
Generally we will have pointer to integers, pointer to characters.
Similar to these things ** is a pointer to another pointer.

Sample pointer to pointer declaration will be like,
Code:

```int **pp; //pp is a pointer to pointer which can points to an integer int *p;//this is a pointer to integer int i=20;//normal integer p = &i; pp = &p; // pp(pointer to pointer) points to p(pointer to integer) which points to i(integer)```