GATE 2019
65 questions
MCQ 41 · NAT 241-mark 30 · 2-mark 35
Questions 36–40 of 65
Consider the following C program:
void convert(int n) {
if (n<0)
printf("%d",n);
else {
convert(n/2);
printf("%d",n%2);
}
} Which one of the following will happen when the function convert is called with any positive integer n as argument?Answer: (D)
When n is positive, n/2 keeps shrinking until it reaches 0. The base case needs n 0, and that never happens. convert(0) just calls convert(0) again and again.
The printf comes after the recursive call, so nothing ever gets printed. The program does not stop (until the stack overflows).
Answer: It will not print anything and will not terminate
The printf comes after the recursive call, so nothing ever gets printed. The program does not stop (until the stack overflows).
Answer: It will not print anything and will not terminate
Consider the following C program:
#include <stdio.h>
int r(){
int static num=7;
return num--;
}
int main() {
for(r();r();r()) {
printf("%d ",r());
};
return 0;
} Which one of the following values will be displayed on execution of the programs?Answer: (B)
num is static. It begins at 7. r() gives back num, then lowers it by 1.
- start: r() 7 (num = 6)
- test: r() 6, true; body prints r() 5
- update: r() 4; test: r() 3, true; body prints r() 2
- update: r() 1; test: r() 0, false loop ends
Output: 5 2
Answer: 52
- start: r() 7 (num = 6)
- test: r() 6, true; body prints r() 5
- update: r() 4; test: r() 3, true; body prints r() 2
- update: r() 1; test: r() 0, false loop ends
Output: 5 2
Answer: 52
Consider three machines M, N and P with IP addresses 100.10.5.2, 100.10.5.5 and 100.10.5.6 respectively. The subnet mask is set to 255.255.255.252 for all the three machines. Which one of the following is true?
Answer: (C)
The mask 255.255.255.252 is /30. So each subnet is a block of 4 addresses in the last octet.
- M has .2 it lies in block .0-.3
- N has .5 it lies in block .4-.7
- P has .6 it lies in block .4-.7
Answer: Only N and P belong to the same subnet
- M has .2 it lies in block .0-.3
- N has .5 it lies in block .4-.7
- P has .6 it lies in block .4-.7
Answer: Only N and P belong to the same subnet
Suppose that in an IP-over-Ethernet network, a machine X wishes to find the MAC address of another machine Y in its subnet. Which one of the following techniques can be used for this?
Answer: (C)
ARP request: X does not know the MAC address of Y. So X sends the request to the broadcast MAC address (FF:FF:FF:FF:FF:FF) in its subnet. The request carries the IP address of Y. Only Y sends a reply, and the reply holds its MAC address.
The gateway has no role here, as Y is in the same subnet. Also, ARP does not use a broadcast IP address.
Answer: X sends an ARP request packet with broadcast MAC address in its local subnet
The gateway has no role here, as Y is in the same subnet. Also, ARP does not use a broadcast IP address.
Answer: X sends an ARP request packet with broadcast MAC address in its local subnet
Consider three 4-variable functions , which are expressed in sum-of-minterms
For the following circuit with one AND gate and one XOR gate, the output function f can be expressed as:
For the following circuit with one AND gate and one XOR gate, the output function f can be expressed as:
Answer: (A)
The circuit gives .
- is the set of shared minterms = {2, 8, 14}
- XOR it with = {2, 7, 11, 14}. Only minterms in just one set stay 2 and 14 drop out, so {7, 8, 11} remain.
Answer:
- is the set of shared minterms = {2, 8, 14}
- XOR it with = {2, 7, 11, 14}. Only minterms in just one set stay 2 and 14 drop out, so {7, 8, 11} remain.
Answer: