Cpp Programming Quiz 52 – Which of the following cannot be used with the keyword virtual?
[B]. member functions[C]. constructor
[D]. destructor
Answer: Option C
Answer: Option C
Answer: Option C
[B].
Answer: Option B
Explanation:
No, Mentioning the array name in C or C++ gives the base address in all contexts except one.
Syntactically, the compiler treats the array name as a pointer to the first element. You can reference elements using array syntax, a[n], or using pointer syntax, *(a+n), and you can even mix the usages within an expression.
When you pass an array name as a function argument, you are passing the “value of the pointer”, which means that you are implicitly passing the array by reference, even though all parameters in functions are “call by value”.
#include
class IndiaBix
{
int x, y, z;
public:
void Apply(int xx = 12, int yy = 21, int zz = 9)
{
x = xx;
y = yy += 10;
z = x -= 2;
}
void Display(void)
{
cout<< x << " " << y << endl;
}
void SetValue(int xx, int yy)
{
Apply(xx, 0, yy);
}
};
int main()
{
IndiaBix *pBix= new IndiaBix;
(*pBix).SetValue(12, 20);
pBix->Display();
delete pBix;
return 0;
}
[A].10 10
[B].12 10
[C].12 21
[D].12 31
Answer: Option A
copy constructor
[C].
destructor
[D].
default constructor
Answer: Option B
Explanation:
No answer description available for this question.
#include
static double gDouble;
static float gFloat;
static double gChar;
static double gSum = 0;
class BaseOne
{
public:
void Display(double x = 0.0, float y = 0.0, char z = 'A')
{
gDouble = x;
gFloat = y;
gChar = int(z);
gSum = gDouble + gFloat + gChar;
cout << gSum;
}
};
class BaseTwo
{
public:
void Display(int x = 1, float y = 0.0, char z = 'A')
{
gDouble = x;
gFloat = y;
gChar = int(z);
gSum = gDouble + gFloat + gChar;
cout << gSum;
}
};
class Derived : public BaseOne, BaseTwo
{
void Show()
{
cout << gSum;
}
};
int main()
{
Derived objDev;
objDev.BaseTwo::Display(10, 20, 'Z');
return 0;
}
[A].The program will print the output 0.
[B].The program will print the output 120.
[C].The program will report run-time error.
[D].The program will report compile-time error.
Answer: Option D
#include
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;
}
[A].The program will print the output 12 97.50 b.
[B].The program will print the output 12 97.50 a.
[C].The program will print the output 12 98 a.
[D].The program will print the output 12 Garbage b.
Answer: Option C