Can't change variable from another function...
I have a function foo()
foo has a local variable var
I want to change var from inside another function
Thus, I figured I would do a call to the other function with &var and then change var by dereferencing it and setting it to its new value.
Apparently this doesn't work... or I am doing something wrong.
Here's what I have (in a nutshell):
Code:
foo () {
unsigned int var = k;
printf("var before: %d\n", var);
bar(&k);
printf("var after: %d\n", var);
}
bar(unsigned int* to_change) {
*to_change = z;
}
=====
[$] ./code
var before: k
var after: k
=====
Why is var not z!?!? And how do I get it to be z??
Edit: I just packed them in a malloc'ed array and changed it that way. Still curious as to how this is done though. I recall something like "Handles" but I couldn't find anything useful in Google.
Edit #2: People shouldn't be allowed to post at 5am... ugh.