Programming and data structure miscellaneous


Programming and data structure miscellaneous

Programming & Data Structure

  1. What will be the output of the following C program ?
       void count (int n){
       static int d=1;

       print f (“%d”, n);
       print f (“%d”, d);
       d++;
       if (n>1) count (n – 1);
       print f (“%d”, d);
    }
      void main( ){
        count(3);
    }









  1. View Hint View Answer Discuss in Forum


    Output will be 312213444.

    Correct Option: A


    Output will be 312213444.


  1. The value printed by the following program is _______.
    void f(int* p, int m){
    m = m + 5;
    *p = *p+m;
    return;
    }
    void main () {
    int i=5, j=10;
    f(& i, j);
    printf (“%d”, i+j);
    }









  1. View Hint View Answer Discuss in Forum

    The address of i and value of j are passed to the function of f. f modifies i’s value to 20. j’s value remains same (as its value is passed not the reference). The value printed by the program will be i + j = 20 + 10 = 30.

    Correct Option: D

    The address of i and value of j are passed to the function of f. f modifies i’s value to 20. j’s value remains same (as its value is passed not the reference). The value printed by the program will be i + j = 20 + 10 = 30.



  1. The attributes of three arithmetic operators in some programming language are given below.
    Operator Precedence Associativity Parity
    + High Left Binary
    Medium Right Binary
    * Low Left Binary

    The value of the expression 2 – 5 + 1 – 7 * 3 in this language is _________.









  1. View Hint View Answer Discuss in Forum

    2 – 5 + 1 – 7 * 3 ⇒ 2 – (5 + 1) – 7 * 3
    ⇒ 2 – 6 – 7 * 3 ⇒ 2 – (6 – 7) * 3 ⇒ 2 – (–1) * 3
    ⇒ (2 + 1) * 3 ⇒ 3 * 3 = 9

    Correct Option: B

    2 – 5 + 1 – 7 * 3 ⇒ 2 – (5 + 1) – 7 * 3
    ⇒ 2 – 6 – 7 * 3 ⇒ 2 – (6 – 7) * 3 ⇒ 2 – (–1) * 3
    ⇒ (2 + 1) * 3 ⇒ 3 * 3 = 9


  1. What will be the output of the following pseudo-code when parameters are passed by reference and dynamic scoping is assumed?
    a = 3;
    void n(x) {x = x * a; print(x);}
    void m(y) {a = 1; a = y – a; n(a); print(a);}
    void main() {m(a);}









  1. View Hint View Answer Discuss in Forum

    Dynamic scoping refers to definition of free variable in the reverse order of calling sequence.

    Correct Option: D

    Dynamic scoping refers to definition of free variable in the reverse order of calling sequence.



  1. The following function computes XY for positive integers X and Y.
    int exp (int X, int Y) {
       int res = 1, a = X, b = Y;
    while (b != 0) {
       if (b%2 == 0) {a = a*a; b = b/2;}
       else      {res = res*a; b = b – 1;}
    }
    return res;
    }
    Which one of the following conditions is TRUE before every iteration of the loop?









  1. View Hint View Answer Discuss in Forum

    Before Iteration 1: X^Y= 64 res * (a^b) = 64
    Before Iteration 2: X^Y= 64 res * (a^b) = 64
    Before Iteration 3: X^Y= 64 res * (a^b) = 64
    Hence, option (c) is verify.

    Correct Option: C

    Before Iteration 1: X^Y= 64 res * (a^b) = 64
    Before Iteration 2: X^Y= 64 res * (a^b) = 64
    Before Iteration 3: X^Y= 64 res * (a^b) = 64
    Hence, option (c) is verify.