0

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 .

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by Aia
0

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);
...
0

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++ .... ????

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.