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 is correct about function overloading?
The types of arguments are different.
The order of argument is different.
The number of argument is same.
Both A and B.
Your Answer: Option
(Not Answered)
Correct Answer: Option

2.
Which of the following is used to make an abstract class?
Declaring it abstract using static keyword.
Declaring it abstract using virtual keyword.
Making at least one member function as virtual function.
Making at least one member function as pure virtual function.
Your Answer: Option
(Not Answered)
Correct Answer: Option

3.
What is correct about the static data member of a class?
A static member function can access only static data members of a class.
A static data member is shared among all the object of the class.
A static data member can be accessed directly from main().
Both A and B.
Your Answer: Option
(Not Answered)
Correct Answer: Option

4.
Which of the following is a mechanism of static polymorphism?
Operator overloading
Function overloading
Templates
All of the above
Your Answer: Option
(Not Answered)
Correct Answer: Option

5.
Which of the following function / type of function cannot be overloaded?
Member function
Static function
Virtual function
Both B and C
Your Answer: Option
(Not Answered)
Correct Answer: Option

6.
Which of the following statement is incorrect?
Default arguments can be provided for pointers to functions.
A function can have all its arguments as default.
Default argument cannot be provided for pointers to functions.
A default argument cannot be redefined in later declaration.
Your Answer: Option
(Not Answered)
Correct Answer: Option

7.
What will be the output of the following program?
#include<iostream.h> 
class Base
{
    public:
    char S, A, M; 
    Base(char x, char y)
    {
        S = y - y;
        A = x + x; 
        M = x * x;
    }
    Base(char, char y = 'A', char z = 'B')
    {
        S = y;
        A = y + 1 - 1; 
        M = z - 1;
    }
    void Display(void)
    {
        cout<< S << " " << A << " " << M << endl;
    }
};
class Derived : public Base
{
    char x, y, z; 
    public:
    Derived(char xx = 65, char yy = 66, char zz = 65): Base(x)
    {
        x = xx; 
        y = yy;
        z = zz;
    }
    void Display(int n)
    {
        if(n)
            Base::Display(); 
        else
            cout<< x << " " << y << " " << z << endl; 
    }
};
int main()
{
    Derived objDev; 
    objDev.Display(0-1); 
    return 0;
}
A A A
A B A
A B C
Garbage Garbage Garbage
The program will report compile time error.
Your Answer: Option
(Not Answered)
Correct Answer: Option

8.
What will be the output of the following program?
#include<iostream.h>
#include<string.h> 
class BixString
{
    char x[50]; 
    char y[50]; 
    char z[50]; 
    public:
    BixString()
    { }
    BixString(char* xx)
    {
        strcpy(x, xx); 
        strcpy(y, xx);
    }
    BixString(char *xx, char *yy = " C++", char *zz = " Programming!")
    {
        strcpy(z, xx); 
        strcat(z, yy); 
        strcat(z, zz);
    } 
    void Display(void)
    {
    cout<< z << endl;
    } 
}; 
int main()
{
    BixString objStr("Learn", " Java");
    objStr.Display();
    return 0; 
}
Java Programming!
C++ Programming!
Learn C++ Programming!
Learn Java Programming!
Learn Java C++ Programming!
Your Answer: Option
(Not Answered)
Correct Answer: Option

9.
Which of the following statements is correct?
  1. Pointer to a reference and reference to a pointer both are valid.
  2. When we use reference, we are actually referring to a referent.
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 statements is correct?
  1. An array of references is acceptable.
  2. We can also create a reference to a reference.
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

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

12.
Which of the following statement is correct?
A reference is a constant pointer.
A reference is not a constant pointer.
An array of references is acceptable.
It is possible to create a reference to a reference.
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

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

15.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class IndiaBix
{
    static int x; 
    public:
    static void SetData(int xx)
    {
        x = xx; 
    }
    static void Display() 
    {
        cout<< x ;
    }
};
int IndiaBix::x = 0; 
int main()
{
    IndiaBix::SetData(44);
    IndiaBix::Display();
    return 0; 
}
The program will print the output 0.
The program will print the output 44.
The program will print the output Garbage.
The program will report compile time error.
Your Answer: Option
(Not Answered)
Correct Answer: Option

16.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class IndiaBix
{
    static int x; 
    public:
    static void SetData(int xx)
    {
        this->x = xx; 
    }
    static void Display() 
    {
        cout<< x ;
    }
};
int IndiaBix::x = 0; 
int main()
{
    IndiaBix::SetData(22);
    IndiaBix::Display();
    return 0; 
}
The program will print the output 0.
The program will print the output 22.
The program will print the output Garbage.
The program will report compile time error.
Your Answer: Option
(Not Answered)
Correct Answer: Option

17.
What happens when a class with parameterized constructors and having no default constructor is used in a program and we create an object that needs a zero-argument constructor?
Compile-time error.
Preprocessing error.
Runtime error.
Runtime exception.
Your Answer: Option
(Not Answered)
Correct Answer: Option

18.
Which constructor function is designed to copy objects of the same class type?
Create constructor
Object constructor
Dynamic constructor
Copy constructor
Your Answer: Option
(Not Answered)
Correct Answer: Option

19.
Destructors __________ for automatic objects if the program terminates with a call to function exit or function abort.
are called
are inherited
are not called
are created
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

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