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
    Answer: Option  D.
accenture article ad
  1. 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) { }
    };
    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
    Answer: Option  D.
  2. 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)++;
    1. a[0] = 2
    2. a[1] = 3
    3. a[1] = 1
    4. 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.
  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
    Answer:Option D.
    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
    Answer:Option B.
    Explanation: do-while loop executed atleast one time, despite of condition is false.
  5. What is the value of variable POLYGON?
    main ( )
    {
    int POLYGON, L, B; L = B = 2;
    POLYGON = (L == B)? 1:0;
    }
    1. 0
    2. 1
    3. 2
    4. 0.5
    Answer:Option B.
    Explanation: ternary operator ( ? Value1: Value2), if condition is true it gives Value1 otherwise Value2.
Campus Placement ad
Rate Us
Views:9399