Originally Posted by
mike65535
He's trying to pass by reference - seems that's the whole point. Passing var to bar won't work (in fact it probably generates a Warning)
In his code k is a magic variable... undeclared and used without initialization, which he passes to the bar() function.
If he wants to change the content of var from bar he needs to actually pass the address of var into the function, not some mystery meat variable from noplace.
Code:
void foo (void)
{
unsigned int var = 09;
printf("var before: %d\n", var);
bar( &var );
printf("var after: %d\n", var);
}
void bar(unsigned int* to_change)
{
*to_change = 31;
}