I have a very general programming question about pointers. I have an integer variable describing the position of an object, x. What I'd like to do is have another variable that takes x and subtracts a constant number off of it. For example, I want a variable y that is equal to x-5. The problem is that I want y to always reflect the current position x without having to call it every time.
I don't want to do this every time I use y:
1 2
y=x-5;
function(y);
Is there any way to do this, maybe using pointers?
My initial thought was trying this:
1 2 3 4 5 6
int x;
int* y;
int z;
y = &x;
z = *y - 5;
But then I realized that it doesn't work.
I know that I could type in x-5 in every instance instead of defining a variable y, but x-5 is a meaningful quantity in my program that has a specific name, and I'd like the code to reflect that by having it assigned its own variable.