Variable with char[] name

后端 未结 3 382
星月不相逢
星月不相逢 2021-01-24 07:15

How can I make variable in C with name specified in char table?

something like:

char name[];
gets(name[]);
int name[] = 0;

I hope you k

3条回答
  •  礼貌的吻别
    2021-01-24 07:31

    C, unlike scripting languages ala Python, or Ruby which you may be used to, is compiled not interpreted. At runtime, C does not have a look up table of variable names like the aforementioned scripting languages, this information is thrown away at compile time and thus, any name that is calculated at run-time cannot be turned into an address.

    Ultimately, as you describe it this is impossible in compiled languages. However, we do have an alternative, found in Collections such as vectors and HashMaps which store naming information at run-time, allowing us to access it. Again, unfortunately, C does not have any native implementations of these, but there are some around.

提交回复
热议问题