C++ Questions

Q:

Which of the following type of data member can be shared by all instances of its class?

A) Public B) Inherited
C) Static D) None
 
Answer & Explanation Answer: C) Static

Explanation:

Static members are shared by all the instances of the class

Report Error

View Answer Report Error Discuss

Filed Under: C++ - Technology

2 9607
Q:

Which design patterns benefit from the multiple inheritance?

A) Adapter and observer pattern B) Code pattern
C) Glue pattern D) None of these
 
Answer & Explanation Answer: A) Adapter and observer pattern

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: C++ - Technology

5 9363
Q:

What is the output of this program?

#include
        using namespace std;
        void fun(int x, int y)
        {
            x = 20;
            y = 10;
        }
        int main()
        {
            int x = 10;
            fun(x, x);
            cout << x;
            return 0;
        }

A) 10 B) 20
C) compile time error D) none of these
 
Answer & Explanation Answer: A) 10

Explanation:

In this program, we called by value so the value will not be changed, So the output is 10

Report Error

View Answer Report Error Discuss

Filed Under: C++ - Technology

0 9277
Q:

How do define the user-defined exceptions?

A) inheriting and overriding exception class functionality. B) overriding class functioality.
C) inheriting class functionality D) none of the mentioned
 
Answer & Explanation Answer: A) inheriting and overriding exception class functionality.

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: C++ - Technology

4 9059
Q:

What is the output of this program?

 #include
       using namespace std;
       int main()
       {
           int arr[] = {4, 5, 6, 7};
           int *p = (arr + 1);
           cout << arr;
           return 0;
       }

A) 4 B) 5
C) address of arr D) 7
 
Answer & Explanation Answer: C) address of arr

Explanation:

As we couted to print only arr, it will print the address of the array.

Report Error

View Answer Report Error Discuss

Filed Under: C++ - Technology

0 8714
Q:

In which of the following we cannot overload the function?

A) return function B) caller
C) called function D) none of the mentioned
 
Answer & Explanation Answer: A) return function

Explanation:

While overloading the return function, it will rise a error, So we can’t overload the return function.

Report Error

View Answer Report Error Discuss

Filed Under: C++ - Technology

2 8113
Q:

Which of the following is not the member of class?

A) Virtual function B) Static function
C) Friend function D) Const function
 
Answer & Explanation Answer: C) Friend function

Explanation:
Report Error

View Answer Report Error Discuss

19 7954
Q:

What is the output of this program?

#include
        using namespace std;
        struct sec {
            int a;
            char b;
        };
        int main()
        {
            struct sec s ={25,50};
            struct sec *ps =(struct sec *)&s;
            cout << ps->a << ps->b;
            return 0;
        }

A) 252 B) 253
C) 254 D) 262
 
Answer & Explanation Answer: A) 252

Explanation:

In this program, We are dividing the values of a and b, printing it.

Report Error

View Answer Report Error Discuss

Filed Under: C++ - Technology

1 7199