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 of the following correctly describes overloading of functions?
Virtual polymorphism
Transient polymorphism
Ad-hoc polymorphism
Pseudo polymorphism
Your Answer: Option
(Not Answered)
Correct Answer: Option

2.
Which of the following is the correct class of the object cout?
iostream
istream
ostream
ifstream
Your Answer: Option
(Not Answered)
Correct Answer: Option

3.
Which of the following cannot be used with the keyword virtual?
class
member functions
constructor
destructor
Your Answer: Option
(Not Answered)
Correct Answer: Option

4.
Which of the following is not a type of constructor?
Copy constructor
Friend constructor
Default constructor
Parameterized constructor
Your Answer: Option
(Not Answered)
Correct Answer: Option

5.
Which of the following statement is correct?
Only one parameter of a function can be a default parameter.
Minimum one parameter of a function must be a default parameter.
All the parameters of a function can be default parameters.
No parameter of a function can be default.
Your Answer: Option
(Not Answered)
Correct Answer: Option

6.
What will be the output of the following program?
#include<iostream.h> 
class TestDrive
{
    int x; 
    public:
    TestDrive(int xx)
    {
        x = xx;
    }
    int DriveIt(void);
};
int TestDrive::DriveIt(void)
{
    static int value = 0;
    int m;
    m = x % 2;
    x = x / 2;
    if((x / 2)) DriveIt(); 
    value = value + m * 10; 
    return value;
}
int main()
{
    TestDrive TD(1234);
    cout<< TD.DriveIt() * 10 << endl;
    return 0; 
}
300
200
Garbage value
400
Your Answer: Option
(Not Answered)
Correct Answer: Option

7.
What will be the output of the following program?
#include<iostream.h> 
struct MyData
{
    public:
    int Addition(int a, int b = 10)
    {
        return (a *= b + 2);
    }
    float Addition(int a, float b);
};
int main()
{
    MyData data;
    cout<<data.Addition(1)<<" ";
    cout<<data.Addition(3, 4);
    return 0; 
}
12 12
12 18
3 14
18 12
Compilation fails.
Your Answer: Option
(Not Answered)
Correct Answer: Option

8.
Functions can be declared to return a reference type. There are reasons to make such a declaration/Which of the following reasons are correct?
  1. The information being returned is a large enough object that returning a reference is more efficient than returning a copy.
  2. The type of the function must be a R-value.
Only 1 is correct.
Only 2 is correct.
Both 1 and 2 are correct.
Both 1 and 2 are incorrect.
Your Answer: Option
(Not Answered)
Correct Answer: Option

9.
Which of the following statements is correct?
  1. A reference is not a constant pointer.
  2. A referenced is automatically de-referenced.
Only 1 is correct.
Only 2 is correct.
Both 1 and 2 are correct.
Both 1 and 2 are incorrect.
Your Answer: Option
(Not Answered)
Correct Answer: Option

10.
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

11.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class IndiaBix
{
    int a, b, c; 
    public:
    void SetValue(int x, int y ,int z)
    {
        a = x;
        b = y;
        c = z;
    } 
    void Display()
    {
        cout<< a << " " << b << " " << c;
    } 
}; 
int main()
{
    IndiaBix objBix;
    int x  = 2;
    int &y = x;
    y = 5;
    objBix.SetValue(x, ++y, x + y);
    objBix.Display();
    return 0; 
}
The program will print the output 5 6 10.
The program will print the output 6 6 10.
The program will print the output 6 6 12.
It will result in a compile time error.
Your Answer: Option
(Not Answered)
Correct Answer: Option

12.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class IndiaBix
{
    int x, y; 
    public:
    void SetValue(int &xx, int &yy)
    {
        x =  xx++;
        y =  yy; 
        cout<< xx << " " << yy;
    }
};
int main()
{
    int x = 10;
    int &y = x;
    IndiaBix objBix;
    objBix.SetValue(x , y);
    return 0; 
}
The program will print the output 10 10.
The program will print the output 10 11.
The program will print the output 11 10.
The program will print the output 11 11.
It will result in a compile time error.
Your Answer: Option
(Not Answered)
Correct Answer: Option

13.
Constructor is executed when _____.
an object is created
an object is used
a class is declared
an object goes out of scope.
Your Answer: Option
(Not Answered)
Correct Answer: Option

14.
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

15.
It is a __________ error to pass arguments to a destructor.
logical
virtual
syntax
linker
Your Answer: Option
(Not Answered)
Correct Answer: Option

16.
Destructor has the same name as the constructor and it is preceded by ______ .
!
?
~
$
Your Answer: Option
(Not Answered)
Correct Answer: Option

17.
A __________ is a constructor that either has no parameters, or if it has parameters, all the parameters have default values.
default constructor
copy constructor
Both A and B
None of these
Your Answer: Option
(Not Answered)
Correct Answer: Option

18.
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

19.
What will be the output of the following program?
#include<iostream.h> 
class BixBase
{
    public:
    int x, y;
    BixBase(int xx = 0, int yy = 5)
    {
        x = ++xx; 
        y = --yy;
    }
    void Display()
    {
        cout<< --y;
    } 
    ~BixBase(){} 
};
class BixDerived : public BixBase
{
    public:
    void Increment()
    {
        y++;
    }
    void Display()
    {
        cout<< --y;
    } 
}; 
int main()
{
    BixDerived objBix;
    objBix.Increment();
    objBix.Display();
    return 0; 
}
3
4
5
Garbage-value
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. "; 
    }
    virtual ~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: