C++

Asked • 08/11/19

What is the lifetime of a static variable in a C++ function?

If a variable is declared as `static` in a function's scope it is only initialized once and retains its value between function calls. What exactly is its lifetime? When do its constructor and destructor get called? void foo() { static string plonk = "When will I die?"; }

1 Expert Answer

By:

Dibyendu D. answered • 02/26/20

Tutor
4.8 (64)

5+ years of experience in programming and teaching C++

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.