Having defined this:
int var1 = 1;
int var2 = 2;
int var3 = 3;
I want to make this:
int result = varc * 70; // Where c is a previously defined int that can take 1,2 or 3 value.
Solutions? Thank you.
In C you're out of luck on this since it's not a reflective language. That is you can't get the value of a variable by somehow "stringifying" the name you gave it in the source code.
But what you could do is use an array:
int vars[] = {1, 2, 3};
int result = vars[i] * 70;
where i is 0, 1, or 2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With