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 an invalid visibility label while inheriting a class?
public
private
protected
friend
Your Answer: Option
(Not Answered)
Correct Answer: Option

2.
Which of the following statements is correct?
Base class pointer cannot point to derived class.
Derived class pointer cannot point to base class.
Pointer to derived class cannot be created.
Pointer to base class cannot be created.
Your Answer: Option
(Not Answered)
Correct Answer: Option

3.
Which of the following concepts means waiting until runtime to determine which function to call?
Data hiding
Dynamic casting
Dynamic binding
Dynamic loading
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

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

6.
Which of the following keyword is used to overload an operator?
overload
operator
friend
override
Your Answer: Option
(Not Answered)
Correct Answer: Option

7.
Which of the following statements regarding inline functions is correct?
It speeds up execution.
It slows down execution.
It increases the code size.
Both A and C.
Your Answer: Option
(Not Answered)
Correct Answer: Option

8.
Which of the following ways are legal to access a class data member using this pointer?
this->x
this.x
*this.x
*this-x
Your Answer: Option
(Not Answered)
Correct Answer: Option

9.
Which of the following statement will be correct if the function has three arguments passed to it?
The trailing argument will be the default argument.
The first argument will be the default argument.
The middle argument will be the default argument.
All the argument will be the default argument.
Your Answer: Option
(Not Answered)
Correct Answer: Option

10.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
static int b = 0; 
void DisplayData(int *x, int *y = &b)
{
    cout<< *x << " " << *y;
}
int main()
{
    int a = 10, b = 20 ;
    DisplayData(&a, &b);
    return 0; 
}
The program will print the output 10 20.
The program will print the output 10 0.
The program will print the output 10 garbage.
The program will report 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 IndiabixSample
{
    private:
    int AdditionOne(int x, int y = 1) 
    {
        return x * y;
    }
     
    public:
    int AdditionTwo(int x, int y = 1)
    {
        return x / y;
    } 
}; 
int main()
{
    IndiabixSample objBix;
    cout<<objBix.AdditionOne(4, 8)<<" "; 
    cout<<objBix.AdditionTwo(8, 8); 
    return 0;
}
The program will print the output 32 0.
The program will print the output 32 garbage-value.
The program will print the output 32 1.
The program will report compile time error.
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

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

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

15.
What does a class hierarchy depict?
It shows the relationships between the classes in the form of an organization chart.
It describes "has a" relationships.
It describes "kind of" relationships.
It shows the same relationship as a family tree.
Your Answer: Option
(Not Answered)
Correct Answer: Option

16.
What happens when we try to compile the class definition in following code snippet?
class Birds {};
class Peacock : protected Birds {};
It will not compile because class body of Birds is not defined.
It will not compile because class body of Peacock is not defined.
It will not compile because a class cannot be protectedly inherited from other class.
It will compile succesfully.
Your Answer: Option
(Not Answered)
Correct Answer: Option

17.
Which of the following can access private data members or member functions of a class?
Any function in the program.
All global functions in the program.
Any member function of that class.
Only public member functions of that class.
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

19.
Which of the following statement is correct whenever an object goes out of scope?
The default constructor of the object is called.
The parameterized destructor is called.
The default destructor of the object is called.
None of the above.
Your Answer: Option
(Not Answered)
Correct Answer: Option

20.
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(char ch)
    {
        cout<< "Char" << 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 Char .
The program will print the output Final .
None of the above
Your Answer: Option
(Not Answered)
Correct Answer: Option

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