I will give a simple example inspired from my problem :

void change(int *x, int *y){x=y;}

int main(){
int *xx,*yy;

yy = (int*)malloc(sizeof(int));
change(xx,yy);

if(xx == NULL)printf("is null\n");
else printf("---- %d ----\n",*xx);

.................................................. .........

xx doesn't point to the value of yy (*yy) , the program prints "is null" . Why ?

xx and yy must be declared int* , it's something that i must do in my program .

Recommended Answers

All 3 Replies

Parameters passed by value in C, so your change function does nothing: it change its local copy of x parameter but not xx argument.
Define then use this (slightly strange) change function as follows:

void change(int** x, int* y)
{
    *x = y;
}
...
change(&xx,yy);
...

10x , the function was a insertion in a BST

void InsertNode(Node *&treeNode, Node *newNode)

i was / am not familiar with what *& means , maybe it's from c++ .... ????

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.