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

2.
Which one of the following is the correct way to declare a pure virtual function?
virtual void Display(void){0};
virtual void Display = 0;
virtual void Display(void) = 0;
void Display(void) = 0;
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

4.
Which of the following function prototype is perfectly acceptable?
int Function(int Tmp = Show());
float Function(int Tmp = Show(int, float));
Both A and B.
float = Show(int, float) Function(Tmp);
Your Answer: Option
(Not Answered)
Correct Answer: Option

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

6.
What is correct about the following program?
#include<iostream.h> 
class Base
{
    int x, y, z; 
    public: 
    Base()
    {
        x = y = z = 0;
    }
    Base(int xx, int yy = 'A', int zz = 'B')
    {
        x = xx;
        y = x + yy;
        z = x + y;
    }
    void Display(void)
    {
        cout<< x << " " << y << " " << z << endl;
    }
};
class Derived : public Base
{
    int x, y; 
    public:
    Derived(int xx = 65, int yy = 66) : Base(xx, yy)
    {
        y = xx; 
        x = yy;
    }
    void Display(void)
    {
        cout<< x << " " << y << " ";
        Display(); 
    }
};
int main()
{
    Derived objD;
    objD.Display();
    return 0; 
}
The program will report compilation error.
The program will run successfully giving the output 66 65.
The program will run successfully giving the output 65 66.
The program will run successfully giving the output 66 65 65 131 196.
The program will produce the output 66 65 infinite number of times (or till stack memory overflow).
Your Answer: Option
(Not Answered)
Correct Answer: Option

7.
What will be the output of the following program?
#include<iostream.h> 
class IndiaBix
{
    public: 
    int x, y;
    IndiaBix(int xx = 10, int yy = 20)
    {
        x = xx;
        y = yy; 
    }
    void Exchange(int *, int *);
};
int main()
{
    IndiaBix objA(30, 40); 
    IndiaBix objB(50); 
    objA.Exchange(&objA.x, &objB.y); 
    cout<< objA.x << " " << objB.y << endl; 
    return 0;
}
void IndiaBix::Exchange(int *x, int *y)
{
    int t;
    t  = *x;
    *x = *y;
    *y = t ; 
}
20 10
30 20
20 30
30 40
50 30
Your Answer: Option
(Not Answered)
Correct Answer: Option

8.
What will be the output of the following program?
#include<iostream.h> 
struct IndiaBix
{
    int arr[5]; 
    public:
    void BixFunction(void);
    void Display(void);
};
void IndiaBix::Display(void)
{
    for(int i = 0; i < 5; i++) 
        cout<< arr[i] << " " ;
}
void IndiaBix::BixFunction(void)
{
    static int i = 0, j = 4; 
    int tmp = arr[i]; 
    arr[i]  = arr[j]; 
    arr[j]  = tmp   ; 
    i++;
    j--;
    if(j != i) BixFunction();
}
int main()
{
    IndiaBix objBix = {{ 5, 6, 3, 9, 0 }};
    objBix.BixFunction();
    objBix.Display();
    return 0; 
}
0 9 3 6 5
9 3 6 5 0
5 6 3 9 0
5 9 3 6 0
Your Answer: Option
(Not Answered)
Correct Answer: Option

9.
Which of the following statement is correct about the program given below?
#include<iostream.h>
long GetNumber(long int Number)
{
    return --Number;
}
float GetNumber(int Number)
{
    return ++Number;
}
int main()
{
    int x = 20;
    int y = 30;
    cout<< GetNumber(x) << " ";
    cout<< GetNumber(y) ;
    return 0; 
}
The program will print the output 19 31.
The program will print the output 20 30.
The program will print the output 21 31.
The program will print the output 21 29.
Program will report compile time error.
Your Answer: Option
(Not Answered)
Correct Answer: Option

10.
Reference is like a _____.
Pointer
Structure
Macro
Enum
Your Answer: Option
(Not Answered)
Correct Answer: Option

11.
Which of the following statements is correct?
  1. Once a reference variable has been defined to refer to a particular variable it can refer to any other variable.
  2. A reference is not a constant pointer.
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 statements is correct?
  1. We can return a global variable by reference.
  2. We cannot return a local variable by 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

13.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
int i, j; 
class IndiaBix
{
    public:
    IndiaBix(int x = 0, int y = 0)
    {
        i = x; 
        j = x; 
        Display();
    }
    void Display()
    {
        cout<< j <<" ";
    } 
}; 
int main()
{
    IndiaBix objBix(10, 20); 
    int &s = i; 
    int &z = j; 
    i++;
    cout<< s-- << " " << ++z; 
    return 0; 
}
The program will print the output 0 11 21.
The program will print the output 10 11 11.
The program will print the output 10 11 21.
The program will print the output 10 11 12.
It will result in a 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> 
class IndiaBix
{
    int x, y; 
    public:
    IndiaBix(int xx = 0, int yy = 0)
    {
        x = xx; 
        y = yy;
    }
    void Display()
    {
        cout<< x << " " << y;
    }
    IndiaBix operator +(IndiaBix z)
    {
        IndiaBix objTemp;
        objTemp.x = x + z.x;
        objTemp.y = y + z.y;
        return objTemp; 
    }
};
int main()
{
    IndiaBix objBix1(90, 80); 
    IndiaBix objBix2(10, 20); 
    IndiaBix objSum; 
    IndiaBix &objRef = objSum; 
    objRef = objBix1 + objBix2; 
    objRef.Display(); 
    return 0; 
}
It will result in a runtime error.
It will result in a compile time error.
The program will print the output 9 4.
The program will print the output 100 100.
Your Answer: Option
(Not Answered)
Correct Answer: Option

15.
Which of the following statement is correct with respect to the use of friend keyword inside a class?
A private data member can be declared as a friend.
A class may be declared as a friend.
An object may be declared as a friend.
We can use friend keyword as a class name.
Your Answer: Option
(Not Answered)
Correct Answer: Option

16.
What will be the output of the following program?
#include<iostream.h>
#include<string.h> 
class IndiaBix
{
    char str[50]; 
    char tmp[50]; 
    public:
    IndiaBix(char *s)
    {
        strcpy(str, s);
    }
    int BixFunction()
    {
        int i = 0, j = 0; 
        while(*(str + i))
        {
            if(*(str + i++) == ' ')
                *(tmp + j++) = *(str + i);
        }
        *(tmp + j) = 0; 
        return strlen(tmp); 
    }
};
int main()
{
    char txt[] = "Welcome to IndiaBix.com!";
    IndiaBix objBix(txt); 
    cout<< objBix.BixFunction();
    return 0;
}
1
2
24
25
Your Answer: Option
(Not Answered)
Correct Answer: Option

17.
Which of the following gets called when an object is being created?
constructor
virtual function
destructor
main
Your Answer: Option
(Not Answered)
Correct Answer: Option

18.
When are the Global objects destroyed?
When the control comes out of the block in which they are being used.
When the program terminates.
When the control comes out of the function in which they are being used.
As soon as local objects die.
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. "; 
    }
};
class BixDerived: public BixBase
{
    public:
    BixDerived()
    { 
        cout<< "Derived OK. "; 
    }
    ~BixDerived()
    { 
        cout<< "Derived DEL. "; 
    }
};
int main()
{
    BixBase    objB;
    BixDerived objD;
    objD.~BixDerived();
    return 0;
}
Base OK. Derived OK. Derived DEL.
Base OK. Base OK. Derived OK. Derived DEL.
Base OK. Derived OK. Derived DEL. Derived DEL.
Base OK. Base OK. Derived OK. Derived DEL. Derived DEL.
The program will report compile time error.
Your Answer: Option
(Not Answered)
Correct Answer: Option

20.
What is the technical word for the function ~IndiaBix() defined in the following program?
#include<iostream.h> 
class IndiaBix
{
    int x, y; 
    public:
    IndiaBix(int xx = 10, int yy = 20 )
    {
        x = xx; 
        y = yy;
    }
    void Display()
    {
        cout<< x << " " << y << endl;
    } 
    ~IndiaBix()
    { } 
};
int main()
{
    IndiaBix objBix; 
    objBix.Display(); 
    return 0;
}
Constructor
Destructor
Default Destructor
Function Template
Your Answer: Option
(Not Answered)
Correct Answer: Option

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