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 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 concepts means adding new components to a program as it runs?
Data hiding
Dynamic typing
Dynamic binding
Dynamic loading
Your Answer: Option
(Not Answered)
Correct Answer: Option

3.
Which of the following is correct about class and structure?
class can have member functions while structure cannot.
class data members are public by default while that of structure are private.
Pointer to structure or classes cannot be declared.
class data members are private by default while that of structure are public by default.
Your Answer: Option
(Not Answered)
Correct Answer: Option

4.
Which of the following concepts means wrapping up of data and functions together?
Abstraction
Encapsulation
Inheritance
Polymorphism
Your Answer: Option
(Not Answered)
Correct Answer: Option

5.
Which of the following provides a reuse mechanism?
Abstraction
Inheritance
Dynamic binding
Encapsulation
Your Answer: Option
(Not Answered)
Correct Answer: Option

6.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
struct MyStructure
{
    class MyClass
    {
        public:
        void Display(int x, float y = 97.50, char ch = 'a')
        {
            cout<< x << " " << y << " " << ch;
        }
    }Cls; 
}Struc;
 
int main()
{
    Struc.Cls.Display(12, 'b');
    return 0; 
}
The program will print the output 12 97.50 b.
The program will print the output 12 97.50 a.
The program will print the output 12 98 a.
The program will print the output 12 Garbage b.
The program will print the output 12 Garbage a.
Your Answer: Option
(Not Answered)
Correct Answer: Option

7.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
static int Result;
class India
{
    public:
    void Change(int x = 10, int y = 20, int z = 30)
    {
        cout<< x + y + z;
    }
    void Display(int x = 40, float y = 50.00)
    {
        Result = x % x; 
        cout<< Result;
    }
};
class Bix
{
    int x, y; 
    public:
    void Change(int x, int y = 50)
    {
        cout<< x + y;
    }
};
class IndiaBix: public India, public Bix
{
    public:
    void Display(int x = 10, int xx = 100, int xxx = 1000)
    {
        Result = x + xx % x * x;
        cout<< Result ; 
    }
};
int main()
{
    IndiaBix objBix;
    objBix.India::Display(10, 20.00);
    return 0; 
}
The program will print the output 0.
The program will print the output 10.
The program will print the output 30.
The program will print the output 40.
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> 
class IndiaBix
{
    int x, y, z; 
    public:
    void Apply(int xx = 12, int yy = 21, int zz = 9)
    {
        x = xx;
        y = yy += 10;
        z = x -= 2;
    }
    void Display(void)
    {
        cout<< x << " " << y << endl; 
    } 
    void SetValue(int xx, int yy)
    {
        Apply(xx, 0, yy);
    }
};
int main()
{
    IndiaBix *pBix= new IndiaBix;
   (*pBix).SetValue(12, 20);
    pBix->Display();
    delete pBix;
    return 0; 
}
10 10
12 10
12 21
12 31
The program will report compilation error.
Your Answer: Option
(Not Answered)
Correct Answer: Option

9.
Which of the following statement is correct?
A referenced has to be de-referenced to access a value.
A referenced does not need to be de-referenced to access a value.
A referenced has to be double de-referenced to access a value.
Whether a reference should be de-referenced or not depends on the type of the reference.
Your Answer: Option
(Not Answered)
Correct Answer: Option

10.
Which of the following statement is correct?
A reference is declared using * operator.
Once a reference variable has been defined to refer to a particular variable it can refer to any other variable.
A reference must always be initialized within classes.
A variable can have multiple references.
Your Answer: Option
(Not Answered)
Correct Answer: Option

11.
Which of the following statement is correct?
A reference is stored on heap.
A reference is stored on stack.
A reference is stored in a queue.
A reference is stored in a binary tree.
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:
    IndiaBix(int &xx, int &yy)
    {
        x = xx;
        y = yy;
        Display();
    }
    void Display()
    {
        cout<< x << " " << y;
    }
};
int main()
{
    int x1 = 10; 
    int &p = x1;
    int y1 = 20; 
    int &q = y1; 
    IndiaBix objBix(p, q); 
    return 0; 
}
It will result in a compile time error.
The program will print the output 10 20.
The program will print two garbage values.
The program will print the address of variable x1 and y1.
Your Answer: Option
(Not Answered)
Correct Answer: Option

13.
Which of the following also known as an instance of a class?
Friend Functions
Object
Member Functions
Member Variables
Your Answer: Option
(Not Answered)
Correct Answer: Option

14.
Which of the following statements is correct when a class is inherited publicly?
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 protected 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>
#include<process.h> 
class IndiaBix
{
    static int x; 
    public:
    IndiaBix()
    {
        if(x == 1)
            exit(0); 
        else
            x++;
    }
    void Display()
    {
        cout<< x << " ";
    }
};
int IndiaBix::x = 0; 
int main()
{
    IndiaBix objBix1; 
    objBix1.Display(); 
    IndiaBix objBix2; 
    objBix2.Display(); 
    return 0; 
}
The program will print the output 1 2.
The program will print the output 0 1.
The program will print the output 1 1.
The program will print the output 1.
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
{
    int x; 
    float y; 
    public:
    void Function()
    {
        x = 4; 
        y = 2.50; delete this;
    }
    void Display()
    {
        cout<< x << " " << y;
    } 
}; 
int main()
{
    IndiaBix *pBix = new IndiaBix();
    pBix->Function(); 
    pBix->Function(); 
    pBix->Display(); 
    return 0; 
}
The program will print the output 4 2.5.
The program will print the output 4.
The program will report runtime error.
The program will report compile time error.
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

18.
Which of the following statement is correct?
A constructor of a derived class can access any public and protected member of the base class.
Constructor cannot be inherited but the derived class can call them.
A constructor of a derived class cannot access any public and protected member of the base class.
Both A and B.
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

20.
What will be the output of the following program?
#include<iostream.h> 
class IndiaBix
{
    int x; 
    public:
    IndiaBix(int xx, float yy)
    {
        cout<< char(yy);
    } 
}; 
int main()
{
    IndiaBix *p = new IndiaBix(35, 99.50f);
    return 0; 
}
99
ASCII value of 99
Garbage value
99.50
Your Answer: Option
(Not Answered)
Correct Answer: Option

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