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?
Your Answer: Option
(Not Answered)
Correct Answer: Option
Discuss about this problem : Discuss in Forum
Learn more problems on : OOPS Concepts
2.
Which one of the following is the correct way to declare a pure virtual function?
Your Answer: Option
(Not Answered)
Correct Answer: Option
Discuss about this problem : Discuss in Forum
Learn more problems on : OOPS Concepts
3.
Which of the following function declaration is/are incorrect?
Your Answer: Option
(Not Answered)
Correct Answer: Option
Discuss about this problem : Discuss in Forum
Learn more problems on : Functions
4.
Which of the following function prototype is perfectly acceptable?
Your Answer: Option
(Not Answered)
Correct Answer: Option
Discuss about this problem : Discuss in Forum
Learn more problems on : Functions
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;
}Your Answer: Option
(Not Answered)
Correct Answer: Option
Discuss about this problem : Discuss in Forum
Learn more problems on : Functions
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;
}Your Answer: Option
(Not Answered)
Correct Answer: Option
Discuss about this problem : Discuss in Forum
Learn more problems on : Functions
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 ;
}Your Answer: Option
(Not Answered)
Correct Answer: Option
Discuss about this problem : Discuss in Forum
Learn more problems on : Functions
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;
}Your Answer: Option
(Not Answered)
Correct Answer: Option
Discuss about this problem : Discuss in Forum
Learn more problems on : Functions
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;
}Your Answer: Option
(Not Answered)
Correct Answer: Option
Discuss about this problem : Discuss in Forum
Learn more problems on : Functions
10.
Reference is like a _____.
Your Answer: Option
(Not Answered)
Correct Answer: Option
Discuss about this problem : Discuss in Forum
Learn more problems on : References
11.
Which of the following statements is correct?
- Once a reference variable has been defined to refer to a particular variable it can refer to any other variable.
- A reference is not a constant pointer.
Your Answer: Option
(Not Answered)
Correct Answer: Option
Discuss about this problem : Discuss in Forum
Learn more problems on : References
12.
Which of the following statements is correct?
- We can return a global variable by reference.
- We cannot return a local variable by reference.
Your Answer: Option
(Not Answered)
Correct Answer: Option
Discuss about this problem : Discuss in Forum
Learn more problems on : References
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;
}Your Answer: Option
(Not Answered)
Correct Answer: Option
Discuss about this problem : Discuss in Forum
Learn more problems on : References
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;
}Your Answer: Option
(Not Answered)
Correct Answer: Option
Discuss about this problem : Discuss in Forum
Learn more problems on : References
15.
Which of the following statement is correct with respect to the use of friend keyword inside a class?
Your Answer: Option
(Not Answered)
Correct Answer: Option
Discuss about this problem : Discuss in Forum
Learn more problems on : Objects and Classes
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;
}Your Answer: Option
(Not Answered)
Correct Answer: Option
Discuss about this problem : Discuss in Forum
Learn more problems on : Objects and Classes
17.
Which of the following gets called when an object is being created?
Your Answer: Option
(Not Answered)
Correct Answer: Option
Discuss about this problem : Discuss in Forum
Learn more problems on : Constructors and Destructors
18.
When are the Global objects destroyed?
Your Answer: Option
(Not Answered)
Correct Answer: Option
Discuss about this problem : Discuss in Forum
Learn more problems on : Constructors and Destructors
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;
}Your Answer: Option
(Not Answered)
Correct Answer: Option
Discuss about this problem : Discuss in Forum
Learn more problems on : Constructors and Destructors
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;
}Your Answer: Option
(Not Answered)
Correct Answer: Option
Discuss about this problem : Discuss in Forum
Learn more problems on : Constructors and Destructors
*** END OF THE TEST ***
Time Left: 00:29:56
Post your test result / feedback here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers