Jump to content

VEX - global variables


Recommended Posts

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?

 

Link to comment
Share on other sites

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 by Guest
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...