Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whether variable name in any programming language takes memory space

e.g.

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

and

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

out of (1) and (2) which will acquire more memory space or equal space would be aquire?

like image 698
Guri Avatar asked Sep 23 '10 11:09

Guri


1 Answers

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.

like image 105
Ferruccio Avatar answered Oct 04 '22 02:10

Ferruccio