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



Loading...  Loading Test...

Instruction:

  • This is a FREE online test. DO NOT pay money to anyone to attend this test.
  • Total number of questions : 20.
  • Time alloted : 30 minutes.
  • Each question carry 1 mark, no negative marks.
  • DO NOT refresh the page.
  • All the best :-).


1.

Which of the following is not a type of constructor?

A.
Copy constructor
B.
Friend constructor
C.
Default constructor
D.
Parameterized constructor

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : OOPS Concepts

Discuss about this problem : Discuss in Forum


2.

Which of the following is an abstract data type?

A.
int
B.
double
C.
string
D.
Class

Your Answer: Option (Not Answered)

Correct Answer: Option D

Learn more problems on : OOPS Concepts

Discuss about this problem : Discuss in Forum


3.

Which of the following approach is adapted by C++?

A.
Top-down
B.
Bottom-up
C.
Right-left
D.
Left-right

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : OOPS Concepts

Discuss about this problem : Discuss in Forum


4.

Which of the following functions are performed by a constructor?

A.
Construct a new class
B.
Construct a new object
C.
Construct a new function
D.
Initialize objects

Your Answer: Option (Not Answered)

Correct Answer: Option D

Learn more problems on : OOPS Concepts

Discuss about this problem : Discuss in Forum


5.

In which of the following a virtual call is resolved at the time of compilation?

A.
From inside the destructor.
B.
From inside the constructor.
C.
From inside the main().
D.
Both A and B.

Your Answer: Option (Not Answered)

Correct Answer: Option D

Learn more problems on : OOPS Concepts

Discuss about this problem : Discuss in Forum


6.

Which of the following statements is correct in C++?

A.
Classes cannot have data as protected members.
B.
Structures can have functions as members.
C.
Class members are public by default.
D.
Structure members are private by default.

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : OOPS Concepts

Discuss about this problem : Discuss in Forum


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; 
}

A.
2 4
B.
6 8
C.
The program will report error on Compilation.
D.
The program will report error on Linking.
E.
The program will report error on Run-time.

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Functions

Discuss about this problem : Discuss in Forum


8.

Which of the following statement is correct about the references?

A.
A reference must always be initialized within functions.
B.
A reference must always be initialized outside all functions.
C.
A reference must always be initialized.
D.
Both A and C.

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : References

Discuss about this problem : Discuss in Forum


9.

Which of the following statement is correct?

A.
Once a reference variable has been defined to refer to a particular variable it can refer to any other variable.
B.
A reference is indicated by using && operator.
C.
Once a reference variable has been defined to refer to a particular variable it cannot refer to any other variable.
D.
A reference can be declared beforehand and initialized later.

Your Answer: Option (Not Answered)

Correct Answer: Option C

Learn more problems on : References

Discuss about this problem : Discuss in Forum


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;
}

A.
The program will print the output 80 80.
B.
The program will print the output 81 80.
C.
The program will print the output 81 81.
D.
It will result in a compile time error.

Your Answer: Option (Not Answered)

Correct Answer: Option D

Learn more problems on : References

Discuss about this problem : Discuss in Forum


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;
}

A.
The program will print the output 80 80.
B.
The program will print the output 81 80.
C.
The program will print the output 81 81.
D.
It will result in a compile time error.

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : References

Discuss about this problem : Discuss in Forum


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; 
}

A.
2 3 6
B.
4 4 7
C.
4 5 8
D.
3 4 6

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : References

Discuss about this problem : Discuss in Forum


13.

Which of the following statement is correct regarding destructor of base class?

A.
Destructor of base class should always be static.
B.
Destructor of base class should always be virtual.
C.
Destructor of base class should not be virtual.
D.
Destructor of base class should always be private.

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Objects and Classes

Discuss about this problem : Discuss in Forum


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; 
}

A.
2
B.
3
C.
5
D.
8

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Objects and Classes

Discuss about this problem : Discuss in Forum


15.

A function with the same name as the class, but preceded with a tilde character (~) is called __________ of that class.

A.
constructor
B.
destructor
C.
function
D.
object

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Constructors and Destructors

Discuss about this problem : Discuss in Forum


16.

Which of the following statements are correct?

A.
Constructor is always called explicitly.
B.
Constructor is called either implicitly or explicitly, whereas destructor is always called implicitly.
C.
Destructor is always called explicitly.
D.
Constructor and destructor functions are not called at all as they are always inline.

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Constructors and Destructors

Discuss about this problem : Discuss in Forum


17.

How many times a constructor is called in the life-time of an object?

A.
Only once
B.
Twice
C.
Thrice
D.
Depends on the way of creation of object

Your Answer: Option (Not Answered)

Correct Answer: Option A

Learn more problems on : Constructors and Destructors

Discuss about this problem : Discuss in Forum


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;
}

A.
Copy constructor
B.
Simple constructor
C.
Non-parameterized constructor
D.
Default constructor

Your Answer: Option (Not Answered)

Correct Answer: Option D

Learn more problems on : Constructors and Destructors

Discuss about this problem : Discuss in Forum


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; 
}

A.
The program will print the output Short .
B.
The program will print the output Int .
C.
The program will print the output Float .
D.
The program will print the output Final .
E.
None of the above

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Constructors and Destructors

Discuss about this problem : Discuss in Forum


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;
}

A.
Base OK. Derived OK.
B.
Base OK. Derived OK. Base DEL.
C.
Base OK. Derived OK. Derived DEL.
D.
Base OK. Derived OK. Derived DEL. Base DEL.
E.
Base OK. Derived OK. Base DEL. Derived DEL.

Your Answer: Option (Not Answered)

Correct Answer: Option B

Learn more problems on : Constructors and Destructors

Discuss about this problem : Discuss in Forum


Submit your test now to view the Results and Statistics with answer explanation.