Code:
int main ( void )
{
int loc1, loc2, loc3;
loc1 = 1;
loc2 = 2;
loc3 = add1( loc1, loc2 );
printf("Loc3 = %d\n", loc3 );
loc1 = 2;
loc2 = 4;
add2( loc1, loc2, &loc3 );
printf("Loc3 = %d\n", loc3 );
return 0;
}
int add1( int one, int two )
{
return one + two;
}
void add2( int one, int two, int *three )
{
if( three != NULL )
{
*three = one + two;
}
}
There are a few ways to do it. In the first example, we just assign the return value of the passed arguments to a variable. In the second, we pass a pointer to the value we want to change, so that changes to said variable in the funtion effect the varaible outside the function call as well.
Quzah.