Online C++ Programming Test - C++ Programming Test - Random

Instruction:

  • This is a FREE online test. Beware of scammers who ask for money to attend this test.
  • Total number of questions: 20.
  • Time allotted: 30 minutes.
  • Each question carries 1 mark; there are no negative marks.
  • DO NOT refresh the page.
  • All the best!

Marks : 2/20


Total number of questions
20
Number of answered questions
0
Number of unanswered questions
20
Test Review : View answers and explanation for this test.

1.
Which one of the following is the correct way to declare a pure virtual function?
virtual void Display(void){0};
virtual void Display = 0;
virtual void Display(void) = 0;
void Display(void) = 0;
Your Answer: Option
(Not Answered)
Correct Answer: Option

2.
Which of the following is an invalid visibility label while inheriting a class?
public
private
protected
friend
Your Answer: Option
(Not Answered)
Correct Answer: Option

3.
Which of the following statements regarding inline functions is correct?
It speeds up execution.
It slows down execution.
It increases the code size.
Both A and C.
Your Answer: Option
(Not Answered)
Correct Answer: Option

4.
Which of the following operators cannot be overloaded?
[]
->
?:
*
Your Answer: Option
(Not Answered)
Correct Answer: Option

5.
Which of the following statement is correct?
C++ enables to define functions that take constants as an argument.
We cannot change the argument of the function that that are declared as constant.
Both A and B.
We cannot use the constant while defining the function.
Your Answer: Option
(Not Answered)
Correct Answer: Option

6.
Which of the following statement is correct about the program given below?
#include<iostream.h>
long GetNumber(long int Number)
{
    return --Number;
}
float GetNumber(int Number)
{
    return ++Number;
}
int main()
{
    int x = 20;
    int y = 30;
    cout<< GetNumber(x) << " ";
    cout<< GetNumber(y) ;
    return 0; 
}
The program will print the output 19 31.
The program will print the output 20 30.
The program will print the output 21 31.
The program will print the output 21 29.
Program will report compile time error.
Your Answer: Option
(Not Answered)
Correct Answer: Option

7.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
int main()
{
    int x = 80; 
    int y& = x;
    x++;
    cout << x << " " << --y;
    return 0;
}
The program will print the output 80 80.
The program will print the output 81 80.
The program will print the output 81 81.
It will result in a compile time error.
Your Answer: Option
(Not Answered)
Correct Answer: Option

8.
Which of the following statements is correct when a class is inherited privately?
Public members of the base class become protected members of derived class.
Public members of the base class become private members of derived class.
Private members of the base class become private members of derived class.
Public members of the base class become public members of derived class.
Your Answer: Option
(Not Answered)
Correct Answer: Option

9.
How many objects can be created from an abstract class?
Zero
One
Two
As many as we want
Your Answer: Option
(Not Answered)
Correct Answer: Option

10.
Which of the following type of data member can be shared by all instances of its class?
Public
Inherited
Static
Friend
Your Answer: Option
(Not Answered)
Correct Answer: Option

11.
What will be the output of the following program?
#include<iostream.h> 
class BixBase
{
    public:
        float x; 
}; 
class BixDerived : public BixBase
{
    public: 
        char ch; 
        void Process()
        {
            ch = (int)((x=12.0)/3.0);
        }
        void Display()
        {
            cout<< (int)ch;
        } 
}; 
int main()
{
    class BixDerived  *objDev = new BixDerived;
    objDev->Process();
    objDev->Display();
    return 0; 
}
The program will print the output 4.
The program will print the ASCII value of 4.
The program will print the output 0.
The program will print the output garbage.
Your Answer: Option
(Not Answered)
Correct Answer: Option

12.
Constructors __________ to allow different approaches of object construction.
cannot overloaded
can be overloaded
can be called
can be nested
Your Answer: Option
(Not Answered)
Correct Answer: Option

13.
Which of the following statement is correct?
A constructor has the same name as the class in which it is present.
A constructor has a different name than the class in which it is present.
A constructor always returns an integer.
A constructor cannot be overloaded.
Your Answer: Option
(Not Answered)
Correct Answer: Option

14.
Which of the following implicitly creates a default constructor when the programmer does not explicitly define at least one constructor for a class?
Preprocessor
Linker
Loader
Compiler
Your Answer: Option
(Not Answered)
Correct Answer: Option

15.
If the copy constructor receives its arguments by value, the copy constructor would
call one-argument constructor of the class
work without any problem
call itself recursively
call zero-argument constructor
Your Answer: Option
(Not Answered)
Correct Answer: Option

16.
Which of the following gets called when an object is being created?
constructor
virtual function
destructor
main
Your Answer: Option
(Not Answered)
Correct Answer: Option

17.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class Bix
{
      int x; 
    public:
      Bix();
      void Show() const;
      ~Bix(){}
};
Bix::Bix()
{
    x = 5;
}
void Bix::Show() const
{
    cout<< x;
}
int main()
{
    Bix objB;
    objB.Show();
    return 0; 
}
The program will print the output 5.
The program will print the output Garbage-value.
The program will report compile time error.
The program will report runtime error.
Your Answer: Option
(Not Answered)
Correct Answer: Option

18.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class IndiaBix
{
    int x; 
    public:
    IndiaBix(short ss)
    {
        cout<< "Short" << endl;
    }
    IndiaBix(int xx)
    {
        cout<< "Int" << endl;
    }
    IndiaBix(float ff)
    {
        cout<< "Float" << endl;
    }
    ~IndiaBix() 
    {
        cout<< "Final";
    }
};
int main()
{
    IndiaBix *ptr = new IndiaBix('B');
    return 0; 
}
The program will print the output Short .
The program will print the output Int .
The program will print the output Float .
The program will print the output Final .
None of the above
Your Answer: Option
(Not Answered)
Correct Answer: Option

19.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class IndiaBix
{
    int x, y; 
    public:
        IndiaBix()
        {
            x = 0;
            y = 0; 
        }
        IndiaBix(int xx, int yy)
        {
            x = xx;
            y = yy; 
        }
        IndiaBix(IndiaBix *objB)
        {
            x = objB->x;
            y = objB->y; 
        }
        void Display()
        {
            cout<< x << " " << y;
        }
};
int main()
{
    IndiaBix objBix( new IndiaBix(20, 40) );
    objBix.Display();
    return 0; 
}
The program will print the output 0 0 .
The program will print the output 20 40 .
The program will print the output Garbage Garbage .
The program will report compile time error.
Your Answer: Option
(Not Answered)
Correct Answer: Option

20.
What will be the output of the following program?
#include<iostream.h>
class BixBase
{   
    public:
    BixBase()
    {
        cout<< "Base OK. "; 
    }
    ~BixBase()
    {
        cout<< "Base DEL. "; 
    }
};
class BixDerived: public BixBase
{
    public:
    BixDerived()
    { 
        cout<< "Derived OK. "; 
    }
    ~BixDerived()
    { 
        cout<< "Derived DEL. "; 
    }
};
int main()
{
    BixBase *basePtr = new BixDerived();
    delete basePtr;
    return 0;
}
Base OK. Derived OK.
Base OK. Derived OK. Base DEL.
Base OK. Derived OK. Derived DEL.
Base OK. Derived OK. Derived DEL. Base DEL.
Base OK. Derived OK. Base DEL. Derived DEL.
Your Answer: Option
(Not Answered)
Correct Answer: Option

*** END OF THE TEST ***
Time Left: 00:29:56
Post your test result / feedback here: