# Technical Questions asked in Huawei

1. 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;
}
1. 300
2. 150
3. 100
4. 200
1. Observe the following code and chose the right statement
class Circle: public Shape
{
Circle(Point, int); // follow this line void draw();
void rotate(int) { }
};
1. Circle(Point, int) is a default constructor in Circle Class
2. Circle(Point, int) is a user defined structure in Circle class
3. Circle(Point, int) is a method declaration in Circle class
4. Circle(Point, int) is a parameterized constructor
2. Which of the following statements is true after execution of the program?
int a,I,*p;
a=1; a=2;p=a;(*p)++;
1. a = 2
2. a = 3
3. a = 1
4. a = 3
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.
3. 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?
1. a = 4, c = 6
2. a = 3, c = 8
3. a = 3, c = 6
4. a = 4, c = 8
b++ means first perform b=b then b=b+1, while ++b means first perform b=b+1.
4. 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. 1
2. 2
3. 9
4. 0.5