C++ Interview Questions

Bjarne-stroustrup
 
Prev13 of 17Next

According to the C++11 standard, what is the output of this program?

#include <iostream>

class A {
public:
	A() { std::cout << "a"; }
	~A() { std::cout << "A"; }
};

class B {
public:
	B() { std::cout << "b"; }
	~B() { std::cout << "B"; }
};

class C {
public:
	C() { std::cout << "c"; }
	~C() { std::cout << "C"; }
};

A a;

void foo() { static C c; }
int main() {
	B b;
	foo();
}

Answer