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

前端 未结 3 1629
星月不相逢
星月不相逢 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:29

    Everything that Henning said before me is correct. In addition, the target of a pointer might not even have a variable name. For example, consider:

    char a;
    char *ptr = &a + 5;
    

    Now ptr is pointing somewhere that doesn't have anything to do with a (and in fact might be pointing outside of the memory allocated for your program and doing anything with that pointer could cause a segmentation fault).

提交回复
热议问题