Is it possible to find out the variable name, the pointer pointing to?

前端 未结 3 1615
星月不相逢
星月不相逢 2020-12-20 00:58

Is it Possible to get the name of array the pointer pointing to?

example:

 char name[20];
 char *p = name
 int door_no;
 int *q = &door_no
         


        
3条回答
  •  隐瞒了意图╮
    2020-12-20 01:18

    No, you can't do that. The names of variables do not even exist after your code is compiled and linked (unless you're keeping debugging information around), so you can't get at it at run time.

    In C (in contrast to very dynamic languages such as JavaScript or classical Lisp), the only role of variable names is to tell the compiler/linker which declaration you're pointing at when you mention a variable in the source code. Once these connections have been made and represented in the compiler's internal data structures, there is no further use for the names (again, except for debugging and/or pretty-printing of error messages from the compiler).

提交回复
热议问题