Whether variable name in any programming language takes memory space

后端 未结 10 1513
时光说笑
时光说笑 2021-01-05 17:44

e.g.

int a=3;//-----------------------(1)

and

int a_long_variable_name_used_instead_of_small_one=3;//-------------(2)
         


        
10条回答
  •  花落未央
    2021-01-05 18:18

    In C++ and most statically compiled languages, variable names may take up more space during the compilation process but by run time the names will have been discarded and thus take up no space at all.

    In interpreted languages and compiled languages which provide run time introspection/reflection the name may take up more space.

    Also, language implementation will affect how much space variable names take up. The implementer may have decided to use a fixed-length buffer for each variable name, in which case each name takes up the same space regardless of length. Or they may have dynamically allocated space based on the length.

提交回复
热议问题