SteveNi Posted January 8, 2017 Share Posted January 8, 2017 Hi Is it possible to modify, from inside a function, a variable that was declared outside that function? For example this code wont work: void functionX() { y = 5; } int y; functionX(); Is there a way to reference that variable inside the function? Quote Link to comment Share on other sites More sharing options...
Guest Posted January 8, 2017 Share Posted January 8, 2017 (edited) void functionX(int var) { var = 5; } int y; printf(itoa(y) + "\n"); //printing out the current y value (0) functionX(y); //we're now passing on the y variable into the function. printf(itoa(y) + "\n"); //y should now be 5 int functionX() { return 5; } int y = functionX(); printf(itoa(y)); Here's 2 methods of doing so. Edited January 8, 2017 by Guest Quote Link to comment Share on other sites More sharing options...
SteveNi Posted January 8, 2017 Author Share Posted January 8, 2017 Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.