0

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?

4
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Red Goose
0

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.

Edited by Ancient Dragon: n/a

0

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;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.