Is it possible to declare a variable in C whose name is specified by the user at runtime?

Is it possible to declare a variable in C whose name is set by the user at runtime? If so, how?

+8
c variables
source share
2 answers

No, this is not possible: variable names do not survive at the compilation stage, becoming addresses and offsets, "baked" in compiled binary code.

However, you can declare a variable whose name is given by the developer at compile time using -D or a comparable option of your C compiler.

+15
source share

As dasblinkenlight answered correctly, no.

What you can do and can achieve your implementation goals is to create and maintain at runtime your own dictionary of strings and related values.

+2
source share

All Articles