What is the output of the following program?
#include
using namespace std;
class base
{
int val1, val2;
public:
int get()
{
val1 = 100;
val2 = 300;
}
friend float mean (base ob);
};
float mean (base ob)
{
return float (ob.val1 + ob.val2) / 2;
}
int main ()
{
base obj;
obj.get ();
cout << mean (obj);
return 0;
}
300
150
100
200
Answer: Option D.
Observe the following code and chose the right statement
class Circle: public Shape
{
Point center; int radius; public:
Circle(Point, int); // follow this line void draw();
void rotate(int) { }
};
Circle(Point, int) is a default constructor in Circle Class
Circle(Point, int) is a user defined structure in Circle class
Circle(Point, int) is a method declaration in Circle class
Circle(Point, int) is a parameterized constructor
Answer: Option D.
Which of the following statements is true after execution of the program?
int a[10],I,*p;
a[0]=1; a[1]=2;p=a;(*p)++;
a[0] = 2
a[1] = 3
a[1] = 1
a[0] = 3
Answer:Option A.
Explanation: base address of array a[] is assigned to p, *p gives value hold by base address, thus (*p)++ increment the value hold by base address by one.
Consider the following program fragment
main ( )
{)
int a,b,c;
b = 2;
a = 2*(b++);
c = 2*(++b);
} Which one of the given answers is correct?
a = 4, c = 6
a = 3, c = 8
a = 3, c = 6
a = 4, c = 8
Answer:Option D.
b++ means first perform b=b then b=b+1, while ++b means first perform b=b+1.
What will be the value of the variable sum after the following program is executed?
main ( )
{
int sum, index;
sum = 1
index = 9;
do {
index = index -1;
sum = 2*sum;
} while (index > 9);
1
2
9
0.5
Answer:Option B.
Explanation: do-while loop executed atleast one time, despite of condition is false.