I have a node struct that has a function which will increment it's valuestruct
node {
int value;
struct node * left;
struct node * right;
void (*incrementValue)(struct node);
};
void incrementNodeValue(struct node this){
this.value ++;
printf("the value is now %d\n", this.value);
}
int main(){
struct node firstLeft = { 5, NULL, NULL, incrementNodeValue };
struct node firstRight = { 15, NULL, NULL, incrementNodeValue };
struct node start = { 10, &firstLeft, &firstRight, incrementNodeValue };
start.incrementValue(start);
printf("%d\n", start.value);
return 0;
}
My intention is that start.incrementValue will increase the value from 10 to 11.
When I compile and run this code (with no warnings), it prints
the value is now 11
10
So I know that the value is changed in the function, but once it exits the function seems no to have had any effect.
error: ',' expected (got "&")thisas a variable name. Everyone will think you're coding c++...