Online C++ Programming Test - C++ Programming Test 2

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 functions are performed by a constructor?
Construct a new class
Construct a new object
Construct a new function
Initialize objects
Your Answer: Option
(Not Answered)
Correct Answer: Option

2.
Which of the following is an abstract data type?
int
double
string
Class
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

4.
Which of the following statements is correct in C++?
Classes cannot have data as protected members.
Structures can have functions as members.
Class members are public by default.
Structure members are private by default.
Your Answer: Option
(Not Answered)
Correct Answer: Option

5.
Which of the following approach is adapted by C++?
Top-down
Bottom-up
Right-left
Left-right
Your Answer: Option
(Not Answered)
Correct Answer: Option

6.
In which of the following a virtual call is resolved at the time of compilation?
From inside the destructor.
From inside the constructor.
From inside the main().
Both A and B.
Your Answer: Option
(Not Answered)
Correct Answer: Option

7.
What will be the output of the following program?
#include<iostream.h> 
class Bix
{
    int x, y; 
    public:
    void show(void);
    void main(void);
};
void Bix::show(void)
{ 
    Bix b;
    b.x = 2;
    b.y = 4;
    cout<< x << " " << y;
}
void Bix::main(void)
{
    Bix b;
    b.x = 6; 
    b.y = 8;
    b.show();
}
int main(int argc, char *argv[])
{
    Bix run;
    run.main();
    return 0; 
}
2 4
6 8
The program will report error on Compilation.
The program will report error on Linking.
The program will report error on Run-time.
Your Answer: Option
(Not Answered)
Correct Answer: Option

8.
Which of the following statement is correct about the references?
A reference must always be initialized within functions.
A reference must always be initialized outside all functions.
A reference must always be initialized.
Both A and C.
Your Answer: Option
(Not Answered)
Correct Answer: Option

9.
Which of the following statement is correct?
Once a reference variable has been defined to refer to a particular variable it can refer to any other variable.
A reference is indicated by using && operator.
Once a reference variable has been defined to refer to a particular variable it cannot refer to any other variable.
A reference can be declared beforehand and initialized later.
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> 
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

12.
What will be the output of the following program?
#include <iostream.h> 
enum xyz 
{
    a, b, c
}; 
int main()
{
    int x = a, y = b, z = c; 
    int &p = x, &q = y, &r = z; 
    p = z; 
    p = ++q;
    q = ++p;
    z = ++q + p++; 
    cout<< p << " " << q << " " << z;
    return 0; 
}
2 3 6
4 4 7
4 5 8
3 4 6
Your Answer: Option
(Not Answered)
Correct Answer: Option

13.
Which of the following statement is correct regarding destructor of base class?
Destructor of base class should always be static.
Destructor of base class should always be virtual.
Destructor of base class should not be virtual.
Destructor of base class should always be private.
Your Answer: Option
(Not Answered)
Correct Answer: Option

14.
What will be the output of the following program?
#include<iostream.h>
#include<string.h> 
class IndiaBix
{
    int val; 
    public:
    void SetValue(char *str1, char *str2)
    {
        val = strcspn(str1, str2);
    }
    void ShowValue()
    {
        cout<< val;
    } 
};
int main() 
{
    IndiaBix objBix;
    objBix.SetValue((char*)"India", (char*)"Bix"); 
    objBix.ShowValue(); 
    return 0; 
}
2
3
5
8
Your Answer: Option
(Not Answered)
Correct Answer: Option

15.
A function with the same name as the class, but preceded with a tilde character (~) is called __________ of that class.
constructor
destructor
function
object
Your Answer: Option
(Not Answered)
Correct Answer: Option

16.
Which of the following statements are correct?
Constructor is always called explicitly.
Constructor is called either implicitly or explicitly, whereas destructor is always called implicitly.
Destructor is always called explicitly.
Constructor and destructor functions are not called at all as they are always inline.
Your Answer: Option
(Not Answered)
Correct Answer: Option

17.
How many times a constructor is called in the life-time of an object?
Only once
Twice
Thrice
Depends on the way of creation of object
Your Answer: Option
(Not Answered)
Correct Answer: Option

18.
Which of the following constructor is used in the program given below?
#include<iostream.h> 
class IndiaBix
{
    int x, y; 
    public:
    IndiaBix(int xx = 10, int yy = 20 )
    {
        x = xx; 
        y = yy;
    }
    void Display()
    {
        cout<< x << " " << y << endl;
    } 
    ~IndiaBix()
    { } 
};
int main()
{
    IndiaBix objBix; 
    objBix.Display(); 
    return 0;
}
Copy constructor
Simple constructor
Non-parameterized constructor
Default constructor
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; 
    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

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: