Loading

SET 1


  Question 1

The output of the following C program is __________.
void f1(int a, int b)
{
int c;
c=a;a=b;b=c;
}
void f2(int *a,int *b){
int c;
c=*a;*a=*b;*b=c;
}
int main()
{
int a=4,b=5,c=6;
f1(a,b);
f2(&b,&c);
printf("%d",c-a-b);
}




  •  
    .

     Correct answer is :-5

     Solution :
     

  •   Question 2

    What is the output of the following C code?
    Assume that the address of X is 2000 (in decimal) and an integer requires four bytes of memory.
    int main()
    {
    unsigned int x [y][z]={ 1,2,3 , 4,5,6 , 7,8,9 , 10,11,12}
    printf("%u %u %u ",x+3,(x+3),(x+2)+3);
    }


    A : 2036, 2036, 2036
    B : 2012,4,2204
    C : 2036,10,10
    D : 2012,4,6


  •  
    .

     Correct answer is :A

     Solution :
      (1) X+3 is treated as address of row „3?
    2000+[3×size of each row]×size of each element
    = 2000+[3×3]×4= 2036
    (2) &(3) are similar to 1


  •   Question 3

    Consider the following pseudo code, where x and y are positive integers.
    begin
    q :=0
    r :=x
    while r>= y do
    begin
    r := r-y
    q: q+1
    end
    end
    The post condition that needs to be satisfied after the program terminates is


    A : {r = qx + y ∧ r < y}
    B : {x = qy + r ∧ r < y}
    C : {y = qx + r ∧ 0 < r < y}
    D : {q + 1 < r – y ∧ y > 0}


  •  
    .

     Correct answer is :B


  •   Question 4

    Consider the following C function.
    int fun1 (int n)
    {
    int i, j, k, p, q = 0;
    for (i = 1; i{
    p = 0;
    for (j=n; j>1; j=j/2)
    ++p;
    for (k=1; k++q;
    }
    return q;
    }
    Which one of the following most closely approximates the return value of the function fun1?


    A : n3
    B : n(log n)2
    C : nlogn
    D : nlogn(logn)


  •  
    .

     Correct answer is :C

     Solution :
      for(i=01;i therefore complexity = nlog(logn)

  •   Question 5

    Consider the following function written the C programming language.
    void foo(char *a) {
    if(*a && *1 != ' ') {
    putchar(*a);
    }
    }
    The output of the above function on input “ABCD EFGH” is


    A : ABCD EFGH
    B : ABCD
    C : HGFE DCBA
    D : DCBA


  •  
    .

     Correct answer is :D


  •   Question 6

    Consider the following C function.
    int fun(int n) {
    int x=1,k;
    if(n==1) return x;
    for(k=1;k x=x+fun(k) * fun(n-k);
    return xl
    }
    The return value of fun (5) is _______




  •  
    .

     Correct answer is :51


  •   Question 7

    Suppose you are provided with the following function declaration in the C programming language
    int partition (int a [ ], int n);
    The function treats the first element of a [ ] as a pivot, and rearranges the array so that all elements less than or equal to the pivot is in the left part of the array , and all elements greater than the pivot is in the right part. In addition, it moves the pivot so that the pivot is the last elements of the left part. The return value is the number of elements in the left part.
    The following partially given function in the C programming language is used to find the Kth smallest element in an array a [ ] of size n using the partition function We assume k<= n .
    int kth _smallest (int a[], int n, int k)
    {
    int left_end=partition(a,n);
    if(left_end +1 ==k){
    return a[left_end];
    }
    if(left_end +1 > k){
    return kth_smallest ( ____________ );
    }else {
    return kth_smallest(______________);
    }
    }
    The miss


    A : (a, left _end,k) and (a + left _end +1, n -left _end -1, k -left _end -1)
    B : (a.left_end,k) and (a,n-left_end-1,k-left_end-1)
    C : (a+left_end+1,n-left_end-1,k-left_end) and (a,left_end,k)
    D : (a,n-left_end-1,k-left_end-1) and (a,left_end ,k)


  •  
    .

     Correct answer is :A


  •   Question 8

    Consider the C program below.
    #include
    Int *A, stkTop;
    Int stkFunc (int opcode, int val)
    {
    Static int size =0, stkTop=0;
    Switch (opcode) {
    Case -1 : Size = val; break;
    Case 0 : if (stkTop < size) A (stktop++] = val; break;
    Default : if (stktop) return A [--stkTop];
    }
    return -1; }
    int main ( )
    {
    int B[20] ; A = B; stkTop = -1;
    stkFunc (-1, 10);
    stkFunc (0, 5);
    stkFunc (0, 10);
    printf (“%d\n”, stkFunc(1, 0) + stkfunc(1, 0);

    }
    The value printed by the above program is _____________.




  •  
    .

     Correct answer is :-2

     Solution :
      StkFunc(1,0) returns -1 both the times. So – 2 will be printed

  •   Question 9

    Consider the following C program segment.
    #include(stdio.h)
    int main()
    {
    char s[7]='1234',*p;
    p=s1+2;
    *p='0';
    printf("%s",s1);
    }
    What will be printed by the program?


    A : 12
    B : 120400
    C : 1204
    D : 1034


  •  
    .

     Correct answer is :C


  •   Question 10

    Suppose c = (c[0],....,c[k - 1]) is an array of length k, where all the entries are from the set {0, 1}. For any positive integers a and n, consider the following pseudo code. DOSOMETHING (c, a, n)
    z <- 1
    for - <- 0 to k-1
    do z <- z2 mod n
    ifc[i]=1
    then z <- (z*a) mod n
    return z
    If k = 4, c =( 1.0,1,1 ), a=2 and n = 8, then the output of DOSOMETHING (c, a, n) is _____________.




  •  
    .

     Correct answer is :0


  •   Question 11

    Consider the following recursive C function.
    Void get (int n)
    {
    if (n< 1) return;
    get (n -1)
    get( n- 3) ;
    pr intf( "%d",n );
    }
    If get (6) function is being called in main () then how many times will the get () function be invoked before returning to the main ( ) ?


    A : 15
    B : 25
    C : 35
    D : 45


  •  
    .

     Correct answer is :B


  •   Question 12

    Consider the following two C code segments. Y and X are one and two dimensional arrays of size n and n × n respectively, where 2 <= n <=10. Assume that in both code segments, elements of Y are initialized to 0 and each element X[i] [j] of array X is initialized to i + j. Further assume that when stored in main memory all elements of X are in same main memory page frame.
    Code segment 1:
    //initialize element of Y to 0
    //initialize elements X[i] [j] of X to 1+j
    For (i = 0; i < n; i++)
    Y[i] + = x[0] [i];

    Code segment 2:
    //initialize elements of Y to 0
    //initialize elements X[i] [j] of X to 1+j
    For (I = 0; i < n; i++)
    Y[i] + = x[i] [0];
    Which of the following statements is/are correct?
    S1: Final contents of array Y will be same in both code segments
    S2: Elements of array X accessed inside the for loop shown in code segment 1 are contiguous in main memory
    S3: Elements of array X accessed inside the for loop shown in co


    A : Only S2 is correct
    B : Only S3 is correct
    C : Only S1 and S2 are correct
    D : Only S1 and S3 are correct


  •  
    .

     Correct answer is :C


  •   Question 13

    Consider the following C program
    #include
    int main ()
    {
    static int a =[10, 20, 30 40, 50] ;
    static int * p =[a, a+ 3, a+ 4, a +1, a+ 2] ;
    int **ptr =p;
    ptr++ ;
    printf( "%d%d", ptr- p, **ptr) ;
    }
    The output of the program is __________.




  •  
    .

     Correct answer is :140


  •   Question 14

    Consider the following C program ( )
    #inclue
    int main
    {
    int i, j, k 0;
    j= 2*3 /4+ 2.0 / 5 +8 / 5;
    k-= - - j;
    for (i= 0; i< 5; i + +)
    {
    Switch (i + k)
    {
    case1:
    case 2 : printf ("\ n%d", i+k);
    case 3: printf( "\ n%d", i+ k);
    default : printf( "\ n%d", i+ k) ;
    }
    Return 0:
    }
    The number of times printf statement is executed is _________.




  •  
    .

     Correct answer is :10

     Solution :
      j and k will be evaluated to 2 and -1 respectively.
    In for loop:
    When i = 0; 1 time printed (-1)
    When i = 1; 1 time printed (0)
    When i = 2; 3 times printed (1,1,1)
    When i = 3; 3 times printed (2,2,2)
    When i = 4; 2 times printed (3,3)
    on the whole printf is executed 10 times

  •   Question 15

    Consider the following C program.
    #include
    int f1 (void) ;
    int f 2 (void)
    ; int x 10;
    int main ()
    {
    int x 1;
    x +=f1()+ f2()+ f3()+ f2() ;
    printf( "%d", x) ;
    return 0;
    }
    int f1() { int x 25; x++ ; return x;}
    int f2()
    { static int x 50; x++ ; return x;}
    int f3(){ x* 10; return x ;}
    The output of the program is_________.




  •  
    .

     Correct answer is :230

     Solution :
      static variable in f2() will be initialized only once & it retains value in between function calls.

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