M
M
Maxim Siomin2020-07-15 13:03:20
C++ / C#
Maxim Siomin, 2020-07-15 13:03:20

Does a variable take up any memory after it is declared?

int x;
Does this variable take up memory?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Victor Bomberow, 2020-07-15
@MaxSiominDev

1) not identified, but not initialized.
2) in this case, the memory is allocated on the stack.

1
15432, 2020-07-15
@15432

Depends on the compiler. I’ll tell you more, only static variables definitely occupy memory, any others can be register

V
Vladimir Kuts, 2020-07-15
@fox_12

intx;
Does this variable take up memory?

It takes about 6 bytes per entry in the code.
When compiling to an executable file, the compiler will remove it the fastest (depending on optimization settings)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question