Well, lets start off w/ the basics:
You're defining variable 'x' w/ file scope (i.e. global to everything in the file), initializing that variable to the integral constant 1 in main() (which, per the ansi standard, should be defined as returning int, not void), calling the function test and passing the _value_ of the global variable x (which is 1, since you initialized it to 1 in main()) as an argument, changing that argument in test() to x, then returning it to the calling function, which is main() in this case. There's quite a few problems here. You're passing the _value of_ x to test(), which means _all_ modifications to x in the scope of test() will be _local_ to that function only. 'x' in the context of test() is in no way associated to the 'x' in the context of the file. You could have also returned the modified value of 'x' to the calling function and handled it appropriately, which you tried to do. Trouble is, you didn't do anything w/ the returning value. You need to do either of these things:
void test(int n)
{
x = n; // this will set the variable 'x' w/ file scope to the value passed to 'n'
}
int main()
{
x = 1;
test(3); // x will now be 3 (bad way to do things)
}
or
void test(int *n)
{
*n = 3; // this will set the variable pointed to by 'n' to 3
}
int main()
{
x = 1;
test(&x); // x will now be 3
}
or
int test(int n)
{
return n;
}
int main()
{
x = 1;
x = test(3); // x will now be 3
}
Well, there you go. All of these are rather pointless, but since you're just trying to understand the ways of things, I hope this helps.
I just typed all of the above here, so, please disregard any 'random functionality' in the above code.