Loading

SET 4


  Question 1

Output of following program?

#include 
int fun(int n, int *f_p)
{
    int t, f;
    if (n ≤ 1)
    {
        *f_p = 1;
        return 1;
    }
    t = fun(n- 1,f_p);
    f = t+ * f_p;
    *f_p = t;
    return f;
}
 
int main()
{
    int x = 15;
    printf (" %d \n", fun(5, &x));
    return 0;
}



A : 6
B : 8
C : 14
D : 15


  •  
    .

     Correct answer is :B


  •   Question 2

    What does the following program print?
    #include
    void f(int *p, int *q)
    {
    p = q;
    *p = 2;
    }
    int i = 0, j = 1;
    int main()
    {
    f(&i, &j);
    printf("%d %d \n", i, j);
    return 0;
    }


    A : 2 2
    B : 2 1
    C : 0 1
    D : 0 2


  •  
    .

     Correct answer is :D


  •   Question 3

    #include
    int f(int *a, int n)
    {
    if(n <= 0) return 0;
    else if(*a % 2 == 0) return *a + f(a+1, n-1);
    else return *a - f(a+1, n-1);
    }
    int main()
    {
    int a[] = {12, 7, 13, 4, 11, 6};
    printf("%d", f(a, 6));
    getchar();
    return 0;
    }


    A : -9
    B : 5
    C : 15
    D : 19


  •  
    .

     Correct answer is :C


  •   Question 4

    The following C function takes a simply-linked list as input argument. It modifies the list by moving the last element to the front of the list and returns the modified list. Some part of the code is left blank.
    typedef struct node 
    {
      int value;
      struct node *next;
    }Node;
      
    Node *move_to_front(Node *head) 
    {
      Node *p, *q;
      if ((head == NULL: || (head->next == NULL)) 
        return head;
      q = NULL; p = head;
      while (p-> next !=NULL) 
      {
        q = p;
        p = p->next;
      }
      _______________________________
      return head;
    }
    
    
    
    
    


    A : q = NULL; p->next = head; head = p;
    B : q->next = NULL; head = p; p->next = head;
    C : head = p; p->next = q; q->next = NULL;
    D : q->next = NULL; p->next = head; head = p;


  •  
    .

     Correct answer is :D


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