Use static or dynamic variables in my codes? What would be more efficient or better seen in the job market?

-1

What's better: Use static or dynamic variables (using pointers in the case) in my codes? What would be more efficient or better seen in the job market? I imagine that each one has its most recommended applications, but I wanted some external opinion. Thank you for your attention!

    
asked by anonymous 09.11.2018 / 23:58

1 answer

1

The labor market has nothing to do with this (the market sees other things, for example conceptualizing things correctly to understand what it is doing and thus produce adequate results, it does not look at a specific point, but the general attitude and capacity of the person). I am responding because the core of the question does not seem to be this.

Variables are not dynamic or static. The closest to this term is the variable being considered static because it is a class variable, as opposed to being an instance variable, in the background the right concept is to be class variable, static is a term used in code only. >

What you're talking about is the objects themselves, they can be statically, automatically, or dynamically allocated.

Static allocation is very simple and occurs at application startup. It's not what you probably think it is. The object already does "part of the code".

What you probably think is static is the automatic allocation that occurs in what is called stack (which can use pointer as well, it is a mistake to associate lifespan or location allocation with the use of pointer). This allocation is always preferable because it costs very cheaply, the release is automatic and so you do not have to worry about managing your life time in a complex way, among other advantages.

Dynamic allocation (occurs in heap and so pointer usage is mandatory since the variable is not there) is used when there is no other way. When you need a longer or less predictable life time, or when it takes up a lot of space.

See more at:

10.11.2018 / 01:53