1

It is always advised to use bigger and clearer variable names in programming suppose I define :

int captain=10 ;

I know that 10 is stored but where is the "captain" or the variable name stored and who allocates memory for it?

dbush
  • 205,898
  • 23
  • 218
  • 273
  • 8
    Variable names are not preserved after compilation, except maybe in debugging symbols. No memory is allocated anywhere for them. – François Andrieux Sep 18 '17 at 18:31
  • The compiler does, to compile the code. Without any debug information, the variable name does not appear in the executable. – Weather Vane Sep 18 '17 at 18:31
  • @ANIRUDDH SHUKLA In books?:) – Vlad from Moscow Sep 18 '17 at 18:45
  • C does not have reflection [1] like Java does so you will not be able to examine the names at run time unless you do some macro tricks to make sure the variable names are available as strings. If you want the variable names for documentation purposes, I suggest using a static analysis tool like doxygen to determine the variable names. [1] https://en.wikipedia.org/wiki/Reflection_(computer_programming) – Gillespie Sep 18 '17 at 18:47
  • FYI: Even when debug symbols are present in the executable, that does not mean that they are loaded into the program's own virtual address space. The _debugger_ will load them, but the debugger typically runs in a separate process. – Solomon Slow Sep 18 '17 at 19:13

1 Answers1

5

In the end they aren't stored anywhere unless you have linked in additional debug information.

They're translated into memory (be it RAM or ROM) addesses and address offsets by your toolchains linker.

user0042
  • 7,917
  • 3
  • 24
  • 39