ProgrammingModerateProduct-company placement · C++

What is printed?

What is printed?
struct L { L() { cout << "L"; } };
void f() { static L l; cout << "f"; }
int main() { f(); f(); f(); }
  1. A. LfLfLf
  2. B. fff
  3. C. LLLfff
  4. D. Lfff

Correct answer: D. Lfff

A static local object is constructed once, the first time control passes through its declaration, and lives until the program ends.

More OOP with C++ and Java questions

Exams that ask this topic