Question from the C++ - Fundamentals test

Write a C++ program that uses static variables.

Expert

What does the following code display ?

class Rectangle {
public:
    static int compteur; 
    Rectangle() {compteur++;}
    ~Rectangle() {compteur--;}
};

int Rectangle::compteur(0);

int main() {

    cout << Rectangle::compteur << endl;
    Rectangle r1;
    cout << Rectangle::compteur << endl;
    {
        Rectangle r2;
    }
    cout << Rectangle::compteur << endl;
    Rectangle r3(r1);
    cout << Rectangle::compteur << endl;
    return 0;
}
Author: SamuelStatus: PublishedQuestion passed 304 times
Edit
1
Community EvaluationsNo one has reviewed this question yet, be the first!