Dynamic variable declaration in C

Prakhar picture Prakhar · May 19, 2011 · Viewed 9k times · Source

I'm a ruby developer and its been long time since I've coded in C. I want to use a datatype in C which behaves like a symbol.

Is this possible?

  • Program asks user for name

  • User replies - "foobar"

  • Program declares an integer with the same name i.e.

    int foobar;
    

Answer

Hyperboreus picture Hyperboreus · May 19, 2011

Unlike in interpreted languages, C does not have a dictionary of variable names at runtime. There exist no variable names at runtime at all. Hence unfortunately it is impossible to do what you want in C.