20.3.2. Exercises: Storage Class

In Example 20.10, identify the scope/storage class of each object's creation/definition. If there is a name clash, describe the error.

[ fromfile: scopestorage.xml id: ex-scopestorage ]

Example 20.10. src/storage/storage.cpp

#include <QString>


int i;                              1
static int j;                       2
extern int k;                       3
const int l=10;                     4
extern const int m=20;              5

class Point                         6
{
    public:
    QString name;                   7
    QString toString() const;
    private:
    static int count;
    int x, y;                       8
};

int Point::count = 0;               9

QString Point::toString() const {
    return QString("(%1,%2)").arg(x).arg(y); 
                                    /* Scope: ______________   Storage class: ____________ */
}

int main(int argc, char** argv)     10
{
    int j;                          11
    register int d;
    int* ip = 0;                    12
    ip = new int(4);                13
    Point p;                        14
    Point* p2 = new Point();        15
}


1

Scope: ______________ Storage class: ____________

2

Scope: ______________ Storage class: ____________

3

Scope: ______________ Storage class: ____________

4

Scope: ______________ Storage class: ____________

5

Scope: ______________ Storage class: ____________

6

Scope: ______________ Storage class: ____________

7

Scope: ______________ Storage class: ____________

8

Scope: ______________ Storage class: ____________

9

Scope: ______________ Storage class: ____________

10

S/SC of argc and argv: _________________

11

Scope: ______________ Storage class: ____________

12

Scope: ______________ Storage class: ____________

13

Scope: ______________ Storage class: ____________

14

Scope: ______________ Storage class: ____________

15

Scope: ______________ Storage class: ____________