Pointers to Members

1

What is the operation for .*?

A. It combines the first operand and the second operand
B. It seperates the first operand and the second operand
C. It reduces the data size
D. None of the mentioned

2

Which is the best design choice for using pointer to member function?

A. Interface
B. Class
C. Structure
D. None of the mentioned

3

What is the output of this program?

1.
    #include 
2.
    using namespace std;
3.
    class Foo
4.
    {
5.
        public:
6.
        Foo(int i = 0){ _i = i;}
7.
        void f()
8.
        {
9.
            cout << "Executed"< f();
18.
    }
A. Executed
B. Error
C. Runtime error
D. None of the mentioned

4

What is the output of this program?

1.
    #include 
2.
    using namespace std;
3.
    class bowl 
4.
    {
5.
        public:
6.
        int apples;
7.
        int oranges;
8.
    };
9.
    int count_fruit(bowl * begin, bowl * end, int bowl :: *fruit)
10.
    {
11.
        int count = 0;
12.
        for (bowl * iterator = begin; iterator != end; ++ iterator)
13.
            count += iterator ->* fruit;
14.
        return count;
15.
    }
16.
    int main()
17.
    {
18.
        bowl bowls[2] = {{ 1, 2 },{ 3, 5 }};
19.
        cout << "I have " << count_fruit(bowls, 
        bowls + 2, & bowl :: apples) << " apples\n";
20.
        cout << "I have " << count_fruit(bowls, bowls + 2, & bowl :: oranges) << " oranges\n";
21.
        return 0;
22.
    }

a) I have 4 apples

I have 7 oranges

b) I have 3 apples

I have 5 oranges

c) I have 1 apples

I have 5 oranges

d) None of the mentioned


5

What is the output of this program?

1.
    #include 
2.
    using namespace std;
3.
    class Car
4.
    {
5.
        public:
6.
        int speed;
7.
    };
8.
    int main()
9.
    {
10.
        int Car :: *pSpeed = &Car :: speed;
11.
        Car c1;
12.
        c1.speed = 1;     
13.
        cout << c1.speed << endl;
14.
        c1.*pSpeed = 2;  
15.
        cout  << c1.speed << endl;
16.
        return 0;
17.
    }
A. 1
B. 2
C. Both a & b
D. None of the mentioned