i dont see how this is possible but....is there a way i can have a literal value in my program....such as the number "1" represent a specific variable?

for example
int sum;

sum = 1 + 3; <--- i want my program to read this as add "3" to the variable which represents the literal "1"....i know this might seem wierd but if this is even possible plz let me know :) thx!

-------------------------------------------------

another example:

read in input
"342" from a file and interpret 4 as a variable instead of treating it as it's normal integer representation?

The answer is no because variable names can not start with a numeric digit. But in c++ you could create a <map> between a digit and something else such as an integer counter.

If you are fine with prepending it with a dash then you can for example :

int _1 = 0;
int var = _1 + 3;

Short answer is no. Your example for "4" could be achieved with a simple if statement. I can't think of a single situation where this couldn't be replaced with something else. If your planning on using 1 in a lot of formulas but may need/want to change them all later you could use a constant or a macro.

#define VARMACRO 1

int main()
{
 int x = VARMACRO;
 return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.