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 access specifier is used as a default in a class definition?
protected
public
private
friend
Your Answer: Option
(Not Answered)
Correct Answer: Option

2.
Which of the following function / types of function cannot have default parameters?
Member function of class
main()
Member function of structure
Both B and C
Your Answer: Option
(Not Answered)
Correct Answer: Option

3.
Which of the following statement is incorrect?
The default value for an argument can be a global constant.
The default arguments are given in the function prototype.
Compiler uses the prototype information to build a call, not the function definition.
The default arguments are given in the function prototype and should be repeated in the function definition.
Your Answer: Option
(Not Answered)
Correct Answer: Option

4.
Which of the following function declaration is/are incorrect?
int Sum(int a, int b = 2, int c = 3);
int Sum(int a = 5, int b);
int Sum(int a = 0, int b, int c = 3);
Both B and C are incorrect.
All are correct.
Your Answer: Option
(Not Answered)
Correct Answer: Option

5.
What will be the output of the following program?
#include<iostream.h> 
typedef void(*FunPtr)(int);
int Look(int = 10, int = 20);
void Note(int); 
int main()
{
    FunPtr ptr = Note;
    (*ptr)(30); 
    return 0;
}
int Look(int x, int y)
{
    return(x + y % 20);
}
void Note(int x)
{
    cout<< Look(x) << endl;
}
10
20
30
40
Compilation fails.
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

7.
What will be the output of the following program?
#include<iostream.h> 
void MyFunction(int a, int b = 40)
{
    cout<< " a = "<< a << " b = " << b << endl;
}
int main()
{
    MyFunction(20, 30);
    return 0; 
}
a = 20 b = 40
a = 20 b = 30
a = 20 b = Garbage
a = Garbage b = 40
Your Answer: Option
(Not Answered)
Correct Answer: Option

8.
What will be the output of the following program?
#include<iostream.h> 
class BaseCounter
{
    protected:
    long int count;

    public:
    void CountIt(int x, int y = 10, int z = 20)
    {
        count = 0;
        cout<< x << " " << y << " " << z << endl;
    } 
    BaseCounter()
    {
        count = 0;
    }
    BaseCounter(int x)
    {
        count = x ;
    } 
}; 
class DerivedCounter: public BaseCounter
{
    public:
    DerivedCounter()
    { }
    DerivedCounter(int x): BaseCounter(x) 
    { }
};
int main()
{
    DerivedCounter objDC(30); 
    objDC.CountIt(40, 50); 
    return 0; 
}
30 10 20
Garbage 10 20
40 50 20
20 40 50
40 Garbage Garbage
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.
Which of the following statement is correct about the references?
A reference must always be initialized within functions.
A reference must always be initialized outside all functions.
A reference must always be initialized.
Both A and C.
Your Answer: Option
(Not Answered)
Correct Answer: Option

11.
Which of the following statements is correct?
  1. A reference is not a constant pointer.
  2. A referenced is automatically de-referenced.
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 about the program given below?
#include<iostream.h> 
int main()
{
    int m = 2, n = 6;
    int &x = m;
    int &y = n;
    m = x++; 
    x = m++;
    n = y++;
    y = n++;
    cout<< m << " " << n; 
    return 0; 
}
The program will print output 2 6.
The program will print output 3 7.
The program will print output 4 8.
The program will print output 5 9.
The program will print output 6 10.
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 BixFunction(int m)
{
    m *= m;
    return((10)*(m /= m)); 
}
int main()
{
    int c = 9, *d = &c, e;
    int &z = e;
    e = BixFunction(c-- % 3 ? ++*d :(*d *= *d));
    z = z + e / 10;
    cout<< c << " " << e;
    return 0;
}
It will result in a compile time error.
The program will print the output 64 9.
The program will print the output 64 10.
The program will print the output 64 11.
Your Answer: Option
(Not Answered)
Correct Answer: Option

14.
Which of the following statements is incorrect?
Friend keyword can be used in the class to allow access to another class.
Friend keyword can be used for a function in the public section of a class.
Friend keyword can be used for a function in the private section of a class.
Friend keyword can be used on main().
Your Answer: Option
(Not Answered)
Correct Answer: Option

15.
Which of the following statement is correct?
Constructor has the same name as that of the class.
Destructor has the same name as that of the class with a tilde symbol at the beginning.
Both A and B.
Destructor has the same name as the first member function of the class.
Your Answer: Option
(Not Answered)
Correct Answer: Option

16.
To ensure that every object in the array receives a destructor call, always delete memory allocated as an array with operator __________ .
destructor
delete
delete[]
kill[]
free[]
Your Answer: Option
(Not Answered)
Correct Answer: Option

17.
A function with the same name as the class, but preceded with a tilde character (~) is called __________ of that class.
constructor
destructor
function
object
Your Answer: Option
(Not Answered)
Correct Answer: Option

18.
Which of the following statement is correct?
A constructor has the same name as the class in which it is present.
A constructor has a different name than the class in which it is present.
A constructor always returns an integer.
A constructor cannot be overloaded.
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

20.
What will be the out of the following program?
#include<iostream.h> 
class BixBase
{
    public:
    int x, y; 
    public:
    BixBase(int xx = 0, int yy = 0)
    {
        x = xx;
        y = yy; 
    } 
 };
class BixDerived : public BixBase
{
    private:
        BixBase objBase; 
    public:
    BixDerived(int xx, int yy) : BixBase(xx), objBase(yy)
    {
        cout << this->x   << " " 
             << this->y   << " "  
             << objBase.x << " "
             << objBase.y << " ";
    } 
    ~BixDerived()
    { }
};
int main()
{
    BixDerived objDev(11, 22); 
    return 0;
}
11 22 0 0
11 0 0 22
11 0 22 0
11 22 11 22
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: