Saving a variable as a variable??
Author |
Message |
Lucas
|
Posted: Thu Mar 24, 2011 7:01 pm Post subject: Saving a variable as a variable?? |
|
|
What is it you are trying to achieve?
I would like to save a number to two different variables, and make it so that if i change the value of one variable, the value of the other variable changes as well
What is the problem you are having?
not sure how do this
Describe what you have tried to solve this problem
asking you guys
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Turing: |
% this is just an example
var a, b : int
a := 55
b := a % I would like it so that it would equal to the variable a, not the value of a. possible?
a := 40
put b % This would ideally output 40, since b = a = 40
|
Please specify what version of Turing you are using
4.1.1 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
|
|
|
|
z_cross_fire
|
Posted: Thu Mar 24, 2011 7:56 pm Post subject: Re: Saving a variable as a variable?? |
|
|
I haven't heard of pointers...and I haven't learnt turing, so this is what I did in C# (if anyone can convert it to turing, it would be helpful to OP)
First, I created a class called SameValue:
code: |
namespace ConsoleApplication2
{
class SameValue
{
public int val;
}
}
|
This is the Main Program:
code: |
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
SameValue a = new SameValue();
SameValue b = a;
a.val = 5;
b.val = 10;
Console.WriteLine(a.val);
Console.Read();
}
}
}
|
The code will print 10.
All this does, is that it gives both 'a' and 'b' access to change the 'val' integer... |
|
|
|
|
|
Tony
|
Posted: Thu Mar 24, 2011 8:02 pm Post subject: RE:Saving a variable as a variable?? |
|
|
@z_cross_fire: "new" returns a pointer |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
|
|