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 concepts means determining at runtime what method to invoke?
Data hiding
Dynamic Typing
Dynamic binding
Dynamic loading
Your Answer: Option
(Not Answered)
Correct Answer: Option

2.
Which one of the following is correct about the statements given below?
  1. All function calls are resolved at compile-time in Procedure Oriented Programming.
  2. All function calls are resolved at compile-time in OOPS.
Only II is correct.
Both I and II are correct.
Only I is correct.
Both I and II are incorrect.
Your Answer: Option
(Not Answered)
Correct Answer: Option

3.
How many types of polymorphisms are supported by C++?
1
2
3
4
Your Answer: Option
(Not Answered)
Correct Answer: Option
Explanation:
The two main types of polymorphism are run-time (implemented as inheritance and virtual functions), and compile-time (implemented as templates).

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

5.
Which of the following is not a type of inheritance?
Multiple
Multilevel
Distributive
Hierarchical
Your Answer: Option
(Not Answered)
Correct Answer: Option

6.
Which of the following statement is correct?
Constructors can have default parameters.
Constructors cannot have default parameters.
Constructors cannot have more than one default parameter.
Constructors can have at most five default parameters.
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

8.
What will be the output of the following program?
#include<iostream.h> 
class Number
{
    int Num; 
    public:
    Number(int x = 0)
    {
        Num = x;
    }
    void Display(void)
    {
        cout<< Num;
    }
    void Modify(); 
};
void Number::Modify()
{
    int Dec;
    Dec = Num % 13; 
    Num = Num / 13; 
    
         if(Num  > 0 ) Modify()   ; 
         if(Dec == 10) cout<< "A" ; 
    else if(Dec == 11) cout<< "B" ; 
    else if(Dec == 12) cout<< "C" ; 
    else if(Dec == 13) cout<< "D" ;
    else               cout<< Dec ;
}
int main()
{
    Number objNum(130);
    objNum.Modify();
    return 0; 
}
130
A0
B0
90
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

10.
What will be the output of the following program?
#include<iostream.h>
#include<string.h> 
class IndiaBix
{
    char txtMsg[50]; 
    public:
    IndiaBix(char *str = NULL)
    {
    if(str != NULL)
       strcpy(txtMsg, str);
    }
    int BixFunction(char ch);
};
int IndiaBix::BixFunction(char ch)
{
    static int i = 0;
    if(txtMsg[i++] == ch)
        return strlen((txtMsg + i)) - i;
    else
        return BixFunction(ch);
}
int main()
{
    IndiaBix objBix("Welcome to IndiaBix.com!");
    cout<< objBix.BixFunction('t');
    return 0;
}
6
8
9
15
16
Your Answer: Option
(Not Answered)
Correct Answer: Option

11.
What will be the output of the following program?
#include<iostream.h>
double BixFunction(double, double, double = 0, double = 0, double = 0);
int main()
{
    double d = 2.3;
    cout<< BixFunction(d, 7) << " ";
    cout<< BixFunction(d, 7, 6) << endl;
    return 0; 
}
double BixFunction(double x, double p, double q, double r, double s)
{
    return p +(q +(r + s * x)* x) * x;
}
7 20
7 19.8
7 Garbage
7 20.8
Your Answer: Option
(Not Answered)
Correct Answer: Option

12.
What will be the output of the following program?
#include<iostream.h> 
class BixTest
{
    public:
    BixTest(int &x, int &y)
    {
        x++;
        y++;
    } 
};
int main()
{
    int a = 10, b = 20;
    BixTest objBT(a, b); 
    cout<< a << " " << b; 
    return 0; 
}
10 20
11 21
Garbage Garbage
It will result in a compile time error.
Your Answer: Option
(Not Answered)
Correct Answer: Option

13.
Which of the following means "The use of an object of one class in definition of another class"?
Encapsulation
Inheritance
Composition
Abstraction
Your Answer: Option
(Not Answered)
Correct Answer: Option

14.
Which of the following never requires any arguments?
Member function
Friend function
Default constructor
const function
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

16.
Can a class have virtual destructor?
Yes
No
Your Answer: Option
(Not Answered)
Correct Answer: Option

17.
If the programmer does not explicitly provide a destructor, then which of the following creates an empty destructor?
Preprocessor
Compiler
Linker
main() function
Your Answer: Option
(Not Answered)
Correct Answer: Option

18.
Which of the following statement is correct?
Destructor destroys only integer data members of the object.
Destructor destroys only float data members of the object.
Destructor destroys only pointer data members of the object.
Destructor destroys the complete object.
Your Answer: Option
(Not Answered)
Correct Answer: Option

19.
What will be the out of the following program?
#include<iostream.h> 
class BixBase
{
    protected:
    int x, y; 
    public:
    BixBase(int xx = 0, int yy = 0)
    {
        x = xx;
        y = yy; 
    } 
    void Show()
    {
        cout<< x * this->y << endl;
    }
};
class BixDerived
{
    private:
        BixBase objBase; 
    public:
    BixDerived(int xx, int yy) : objBase(xx, yy)
    {
        objBase.Show();
    } 
    ~BixDerived()
    { }
};
int main()
{
    BixDerived objDev(10, 20); 
    return 0;
}
0
100
200
400
The program will report compile time error.
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 *p; 
    public:
    IndiaBix(int xx, char ch)
    {
        p  = new int(); 
        *p = xx + int(ch); 
        cout<< *p;
    }
    ~IndiaBix() 
    {
        delete p;
    }
};
int main()
{
    IndiaBix objBix(10, 'B'); 
    return 0;
}
The program will print the output 76.
The program will print the output 108.
The program will print the output 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: