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

Asked

Viewed 110 times

-1

What’s better: Using static or dynamic variables (using pointers in the case) in my codes? What would be more efficient or better seen in the labour market? I imagine that each one has its most recommended applications, but wanted some outside opinion. Thanks for the attention!

  • 1

    This is not an objective question. It depends entirely on the case at hand, and so there is no rule that is always to one side or the other.

  • Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful for you. You can also vote on any question or answer you find useful on the entire site (when you have 15 points).

  • Yes. It was helpful, thank you.

1 answer

1

The labor market has nothing to do with it (the market sees other things, for example conceptualizing things correctly to understand what it is doing and thus producing adequate results, it does not look at a specific point, but the general attitude and ability of the person). I am answering 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, these can be allocated in a static, automatic or dynamic way.

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

What you probably think is static is the automatic allocation that takes place in what is called stack (which can use pointer too, it is an error to associate the lifetime or location of allocation with the use of pointer). This allocation is always preferable because it costs too cheap, the release is automatic and so you don’t have to worry about managing your life time in a complex way, among other advantages.

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

See more in:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.