If I have this:
int a = 2;
int b = 4;
int &ref = a;
How can I make ref refer to b after this code?
You can't reassign a reference, but if you're looking for something that would provide similar abilities to this you can do a pointer instead.
int a = 2;
int b = 4;
int* ptr = &a; //ptr points to memory location of a.
ptr = &b; //ptr points to memory location of b now.
You can get or set the value within pointer with:
*ptr = 5; //set
int c = *ptr; //get