GATE CS Mock 2018 | Set 2

Last Updated :
Discuss
Comments

Question 1

What is output of following C - Code? C
#include <stdio.h>
#include <stdarg.h>
int fun(int n, ...)
{
    int i, j = 1, val = 0;
    va_list p;
    va_start(p, n);
    for (; j < n; ++j)
    {
        i = va_arg(p, int);
        val += i;
    }
    va_end(p);
    return val;
}
int main()
{
    printf("%d\\n", fun(4, 1, 2, 3));
    return 0;
}
  • 3
  • 5
  • 6
  • 10

Question 2

Consider the following C - code :

C
#include <stdio.h>

int foo(int a)
{
 	printf("%d",a);
	return 0;
}

int main()
{
 	foo;
 	return 0;
}


  • It’ll result in compile error because foo is used without parentheses.

  • No compile error and some garbage value would be passed to foo function. This would make foo to be executed with output “garbage integer”.

  • No compile error but foo function wouldn’t be executed. The program wouldn\'t print anything.

  • No compile error and ZERO (i.e. 0) would be passed to foo function. This would make foo to be executed with output 0.

Question 3

What’s going to happen when we compile and run the following C program snippet? C
#include "stdio.h"
int main()
{
 int a = 10;
 int b = 15;

 printf("=%d",(a+1),(b=a+2));
 printf(" %d=",b);

 return 0;
}
  • =11 15=
  • =11 12=
  • Compiler Error due to (b=a+2) in the first printf().
  • No compile error but output would be =11 X= where X would depend on compiler implementation.

Question 4

Which of the following is/are not shared by all the threads in a process?
I. Program Counter

II. Stack

III. Registers

IV. Address space
  • I and II only
  • II and III only
  • I, II and III only
  • IV only

Question 5

Consider the set of processes with arrival time(in milliseconds), CPU burst time (in milliseconds), and priority(0 is the highest priority) shown below. None of the processes have I/O burst time. g2017_12 The waiting time (in milliseconds) of process P1 using preemptive priority scheduling algorithm is ____.

  • 26
  • 49
  • 38
  • 29

Question 6

Consider a link with packet loss probability of 0.2. What is the expected number of transmissions it would take to transfer 200 packets given that the stop and wait protocol is used?

  • 125

  • 250

  • 225

  • 150

Question 7

Which of the following statement is False about the efficiency of the given channel?
  • If we want to send big packets on the channel, then Stop and Wait is good choice.
  • If length of packet increases, efficiency of channel also increases.
  • Distance between sender and receiver is directly proportional to efficiency of channel.
  • Efficient might be less if capacity of channel is high.

Question 8

Match the following: Capture33 Which of the following option is correct?

  • A – 3, B – 2, C – 4, D – 1
  • A – 3, B – 1, C – 4, D – 2
  • A – 3, B – 4, C – 2, D – 1
  • A – 1, B – 2, C – 4, D – 3

Question 9

Which of the following option is false?
  • Internal fragmentation occurs when total memory space exists to satisfy the a request, but it is not contiguous. External fragmentation occurs when allocated memory may be slightly larger the requested memory, this size difference is memory internal to a partition,but not being used.
  • Pure paging does not have external fragmentation, but may have internal fragmentation and Pure segmentation may have external fragmentation.
  • Both (A) and (B)
  • Neither (A) nor (B)

Question 10

Huffman coding is a lossless data compression algorithm. The most frequent character gets the smallest code and the least frequent character gets the largest code. Consider the following statements regarding Huffman coding algorithm? 

S1 : The time complexity of the Huffman algorithm is O(nlogn). Using a heap to store the weight of each tree, each iteration requires O(logn) time to determine the cheapest weight and insert the new weight. There are O(n) iterations, one for each item. 

S2 : If the input array is sorted, there exists a linear time algorithm. 

S3 : A divide-and-conquer approach might have us asking which characters should appear in the left and right subtrees and trying to build the tree from the top down. As with the optimal binary search tree, this will lead to to an exponential time algorithm. 

Which of the following option is correct?

  • Statement S1 is correct, Statements S2 and S3 are not correct.

  • Statements S1 and S2 are correct and statement S3 is not correct.

  • Statements S2 and S3 are correct and statement S1 is not correct.

  • All statements S1, S2, and S3 are correct.

Tags:

There are 64 questions to complete.

Take a part in the ongoing discussion