Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3
Well, as everyone is saying, technically i think it's impossible, but I have an idea: You can create a dictionary. If you think about it, the way dictionaries work make them suitable for storing "variables". Just set the key as the user input and the value as the value of the "variable" with that name. When you want to access the value, just search in the dictionary indexing the key: the "name" of the value. I made an example with Python for you to see: https://code.sololearn.com/clIBtHe32S3S/?ref=app
6th Sep 2019, 9:00 PM
Ángel Daniel
Ángel Daniel - avatar
+ 7
I think it is impossible Because the process of creating each variable is done at compile time what is the benefit of this tricky ?
5th Sep 2019, 11:28 PM
ABADA S
ABADA S - avatar
+ 4
Yes, php has this ability. They are called "variable variables".
6th Sep 2019, 1:37 PM
Zeke Williams
Zeke Williams - avatar
+ 2
I don't know of any way that is possible in C++. If there is, it would probably be some hacky work around way that wouldn't be easy.
5th Sep 2019, 10:35 PM
Zeke Williams
Zeke Williams - avatar
+ 2
I think it's impossible . We can store a value to a variable by taking input from the user but we cannot take variable name as a input , we can only take values.
6th Sep 2019, 10:12 AM
Sagnik Ray
Sagnik Ray - avatar