Cpp Programming 80 – Which of the following ways are legal to access a class data member using this pointer?
[B]. this.x[C]. *this.x
[D]. *this-x
Answer: Option A
Answer: Option A
[B].
[C].
[D].
Answer: Option C
Explanation:
The statement ‘C’ is correct. When we pass an array as a funtion argument, the base address of the array will be passed.
#include
class IndiaBix
{
int x;
float y;
public:
void Function()
{
x = 4;
y = 2.50; delete this;
}
void Display()
{
cout<< x << " " << y;
}
};
int main()
{
IndiaBix *pBix = new IndiaBix();
pBix->Function();
pBix->Function();
pBix->Display();
return 0;
}
[A].The program will print the output 4 2.5.
[B].The program will print the output 4.
[C].The program will report runtime error.
[D].The program will report compile time error.
Answer: Option C
Answer: Option C
Answer: Option C
#include
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;
}
[A].7 20
[B].7 19.8
[C].7 Garbage
[D].7 20.8
Answer: Option D
Answer: Option D