Loading

SET 2


  Question 1

Consider the following program in C language:
# include
main ()
{
int i;
int * pi =&i;
scanf( "%d", pi );
printf( "%d \ n", i+5) ;
}
Which one of the following statements is TRUE?


A : Compilation fails.
B : Execution results in a run-time error.
C : On execution, the value printed is 5 more than the address of variable i.
D : On execution, the value printed is 5 more than the integer value entered.


  •  
    .

     Correct answer is :D

     Solution :
      pi contains the address of i. So scanf("%d",pi) places the value entered in console into variable i.e So printf("%d\n",i+5),prints 5 more than the value entered in console.

  •   Question 2

    Consider the following C function in which size is the number of elements in the array E:
    int MyX(int *E, unsigned int size)
    {
    int Y = 0;
    int Z;
    int i, j, k;
    for(i = 0; i < size; i++)
    Y = Y + E[i];
    for(i = 0; i < size; i++)
    for(j = i; j < size; j++)
    {
    Z = 0;
    for(k = i; k <= j; k++)
    Z = Z + E[k];
    if (Z > Y)
    Y = Z;
    }
    return Y;
    }
    The value returned by the function MyX is the


    A : maximum possible sum of elements in any sub-array of array E.
    B : maximum element in any sub-array of array E.
    C : sum of the maximum elements in all possible sub-arrays of array E.
    D : the sum of all the elements in the array E.


  •  
    .

     Correct answer is :A


  •   Question 3

    Consider the following pseudo code. What is the total number of multiplications to be performed?
    D= 2
    for i = 1 to n do
    for j = i to n do
    for k = j + 1 to n do
    D = D * 3


    A : Half of the product of the 3 consecutive integers
    B : One-third of the product of the 3 consecutive integers.
    C : One-sixth of the product of the 3 consecutive integers.
    D : None of the above.


  •  
    .

     Correct answer is :C


  •   Question 4

    Consider the function func shown below:
    int func(int num)
    {
    int count = 0;
    while (num)
    {
    count++;
    num>>= 1;
    }
    return (count);
    }
    The value returned by func(435)is __________.




  •  
    .

     Correct answer is :9


  •   Question 5

    For a C program accessing X[i] [j] [k], the following intermediate code is generated by a compiler. Assume that the size of an integer is 32 bits and the size of a character is 8 bits.
    t0 = i * 1024
    t1 = j * 32
    t2 = k * 4
    t3 = t1 + t0
    t4 = t3 + t2
    t5 = X[t4]
    Which one of the following statements about the source code for the C program is CORRECT?


    A : X is declared as “int X[32] [32] [8]”.
    B : X is declared as “int X[4] [1024] [32]”.
    C : X is declared as “char X[4] [32] [8]”.
    D : X is declared as “char X[32] [16] [2]”.


  •  
    .

     Correct answer is :A

     Solution :
      It is given that Size of int is 4B and of char is 1B. The memory is byte addressable. Let the array be declared as Type X[A][B][C] (where Type = int/char and A,B,C are natural numbers).
    From t0 = i*1024, we conclude that B*C*(size of Type) = 1024.
    From t1 = j*32, we conclude that C*(size of Type) = 32.
    From t2 = k*4, we conclude that size of Type = 4.
    Type = int, and 
    C = 8, and
     B = 32.

  •   Question 6

    Consider the following function
    double f (double x) {
    if ( abs (x*x – 3) < 0. 01) return x;
    else return f (x / 2 + 1.5/x);
    }
    Give a value q (to 2 decimals) such that f (q) will return q:______




  •  
    .

     Correct answer is :1.72 - 1.74

     Solution :
      If condition given in function definition should be ‘TRUE’, for f (q) to return value q. The condition is as follows:
    if (abs(x ×x - 3)<0.01) return x;
    The above condition will be true when x=1.73.

  •   Question 7

    Consider the C function given below
    int f(int j)
    {
    static int i = 50;
    int k;
    if (i == j)
    {
    printf(“something”);
    k = f(i);
    return 0;
    }
    else return 0;
    }
    Which one of the following is TRUE?


    A : The function returns 0 for all values of j.
    B : The function prints the string something for all values of j.
    C : The function returns 0 when j = 50.
    D : The function will exhaust the runtime stack or run into an infinite loop when j = 50.


  •  
    .

     Correct answer is :D

     Solution :
      For any value of ‘j’ other than 50 the function will return 0, for j=50, then condition (i==j) will be true, it will print “something” and function will be called recursively with same value till the run time stack overflows.

  • MY REPORT
    TOTAL = 7
    ANSWERED =
    CORRECT / TOTAL = /7
    POSITIVE SCORE =
    NEGATIVE SCORE =
    FINAL SCORE =