GATE 2022
65 questions
MCQ 32 · MSQ 15 · NAT 181-mark 30 · 2-mark 35
Questions 21–25 of 65
What is printed by the following ANSI C program?
#include <stdio.h>
int main(int argc, char *argv[])
{
int x = 1, z[2] = {10, 11};
int *p=NULL; p=&x;
*p=10;
p =&z[1];
*(&z[0]+1)+=3;
printf("%d, %d, %d \n",x,z[0],z[1]); return 0;
}
Answer: (D)
Go through the program one line at a time:
- p is set to x. Then *p = 10 gives x = 10
- Next, p is set to z[1]. p is not used after this.
- The expression means z[1]. So z[1] += 3 gives z[1] = 14
- z[0] is not changed, so 10
The program prints: 10, 10, 14
Answer: 10, 10, 14
- p is set to x. Then *p = 10 gives x = 10
- Next, p is set to z[1]. p is not used after this.
- The expression means z[1]. So z[1] += 3 gives z[1] = 14
- z[0] is not changed, so 10
The program prints: 10, 10, 14
Answer: 10, 10, 14
Consider an enterprise network with two Ethernet segments, a web server and a firewall, connected via three routers as shown below.
What is the number of subnets inside the enterprise network?
What is the number of subnets inside the enterprise network?
Answer: (C)
Each link between router interfaces is its own subnet. Each LAN behind a router is also its own subnet:
1. Firewall - left router
2. Firewall - top router
3. Top router - web server
4. Top router - right router
5. Left router - left Ethernet
6. Right router - right Ethernet
Answer: 6
1. Firewall - left router
2. Firewall - top router
3. Top router - web server
4. Top router - right router
5. Left router - left Ethernet
6. Right router - right Ethernet
Answer: 6
Which of the following statements is/are TRUE?
One or more options are correct.
Answer: (B), (C), (D)
Check each statement:
- (A) A subset of an RE language does not have to be recursive. is regular, so it is recursive and RE. The halting language is a subset of but it is not recursive. FALSE.
- (B) Suppose and are both RE. Run both recognizers at the same time. Every string is in or in , so one of them must accept. If it is the machine for , accept; if it is the machine for , reject. So is recursive. TRUE.
- (C) Every CFL is recursive, and recursive languages are closed under complement. TRUE.
- (D) is regular, and every regular language is deterministic context-free. TRUE.
Answer: (B), (C), (D)
- (A) A subset of an RE language does not have to be recursive. is regular, so it is recursive and RE. The halting language is a subset of but it is not recursive. FALSE.
- (B) Suppose and are both RE. Run both recognizers at the same time. Every string is in or in , so one of them must accept. If it is the machine for , accept; if it is the machine for , reject. So is recursive. TRUE.
- (C) Every CFL is recursive, and recursive languages are closed under complement. TRUE.
- (D) is regular, and every regular language is deterministic context-free. TRUE.
Answer: (B), (C), (D)
Let WB and WT be two set associative cache organizations that use LRU algorithm for cache block replacement. WB is a write back cache and WT is a write through cache. Which of the following statements is/are FALSE?
One or more options are correct.
Answer: (A), (B), (D)
We need the FALSE statements.
(A) FALSE. A write through cache writes to memory on every write, so it needs no dirty bit. Only WB has one.
(B) FALSE. A write hit in WB only updates the cache and sets the dirty bit. Memory is updated later, when the block is evicted.
(C) TRUE. Memory is already up to date in WT, so evicting a block needs no transfer to memory.
(D) FALSE. The LRU victim chosen on a read miss in WB can be dirty.
Answer: (A), (B), (D)
(A) FALSE. A write through cache writes to memory on every write, so it needs no dirty bit. Only WB has one.
(B) FALSE. A write hit in WB only updates the cache and sets the dirty bit. Memory is updated later, when the block is evicted.
(C) TRUE. Memory is already up to date in WT, so evicting a block needs no transfer to memory.
(D) FALSE. The LRU victim chosen on a read miss in WB can be dirty.
Answer: (A), (B), (D)
Consider the following three relations in a relational database.
Which of the following relational algebra expressions return the set of who own all the brands?
Which of the following relational algebra expressions return the set of who own all the brands?
One or more options are correct.
Answer: (A), (B)
"Owns all brands" is a division by the set of all brands. An employee qualifies if the pair (employee, brand) is in Own for every brand.
(A) is exactly this division. TRUE.
(B) gives every (owner, brand) pair. Subtracting leaves the pairs where the employee does not own that brand. Projecting to gives the employees who miss at least one brand. Removing them from leaves the employees who own every brand. This is the expanded form of division. TRUE.
(C) It divides by , the brands owned by someone, not by all brands. If some brand is owned by nobody, an employee who owns every owned brand is returned although he does not own all brands. WRONG.
(D) The dividend pairs every owner with every owned brand. Dividing by returns all owners if every brand is owned by someone, and the empty set otherwise. It does not depend on who owns what. WRONG.
Answer: (A), (B)
(A) is exactly this division. TRUE.
(B) gives every (owner, brand) pair. Subtracting leaves the pairs where the employee does not own that brand. Projecting to gives the employees who miss at least one brand. Removing them from leaves the employees who own every brand. This is the expanded form of division. TRUE.
(C) It divides by , the brands owned by someone, not by all brands. If some brand is owned by nobody, an employee who owns every owned brand is returned although he does not own all brands. WRONG.
(D) The dividend pairs every owner with every owned brand. Dividing by returns all owners if every brand is owned by someone, and the empty set otherwise. It does not depend on who owns what. WRONG.
Answer: (A), (B)