GATE 2017 (Session 1)
64 questions
MCQ 44 · NAT 201-mark 30 · 2-mark 34
Questions 21–25 of 64
Consider the C struct defined below:
struct data {
int marks [100] ;
char grade;
int cnumber;
};
struct data student; The base address of student is available in register R1. The field student.grade can be accessed efficiently usingAnswer: (D)
The array has 100 ints. With 4-byte ints it takes 400 bytes, and comes right after it, so is at a fixed offset of 400 bytes from the start of the struct. Its address is R1 + 400.
Index (displacement) addressing, , forms exactly this address. The offset fits easily in a 16-bit 2's complement number.
The others cannot do it efficiently:
- (R1)+ reaches only the address in R1 (the start of the struct), then increments R1.
- -(R1) first decrements R1 and so reaches the memory before the struct.
- Register direct, R1, uses the register's own value as the operand, not a memory location.
Answer: (D)
Index (displacement) addressing, , forms exactly this address. The offset fits easily in a 16-bit 2's complement number.
The others cannot do it efficiently:
- (R1)+ reaches only the address in R1 (the start of the struct), then increments R1.
- -(R1) first decrements R1 and so reaches the memory before the struct.
- Register direct, R1, uses the register's own value as the operand, not a memory location.
Answer: (D)
Consider the following intermediate program in three address code
p= a -b
q= p *c
p= u * v
q= p + q
Which one of the following corresponds to a static single assignment form of the above code?
p= a -b
q= p *c
p= u * v
q= p + q
Which one of the following corresponds to a static single assignment form of the above code?
Answer: (B)
The original code is , , , . In SSA, each name is assigned exactly once, and every use refers to the latest version of that variable (the subscript numbers themselves do not matter).
(B) , , , . Every name is assigned once. uses the first (). The last statement uses the second () and the first (). So it is correct.
(A) assigns twice and twice, so it is not SSA.
(C) uses , and , which are never assigned.
(D) uses plain and (in and in the last statement) instead of subscripted names.
Answer: (B)
(B) , , , . Every name is assigned once. uses the first (). The last statement uses the second () and the first (). So it is correct.
(A) assigns twice and twice, so it is not SSA.
(C) uses , and , which are never assigned.
(D) uses plain and (in and in the last statement) instead of subscripted names.
Answer: (B)
Consider the following C code:
#include <stdio.h>
int * assignval (int *x, int val) {
*x = val;
return x;
}
void main ( ) {
int * x= malloc (sizeof (int));
if (NULL == x) return;
x = assignval (x,0);
if(x) {
x=(int *) malloc (sizeof (int));
if (NULL == x) return;
x = assignval (x, 10);
}
printf("%d\n", *x);
free (x);
} The code suffers from which one of the following problems:Answer: (D)
The first malloc block, which holds 0, is never freed. The pointer x is given a new address by the second malloc, so the first block cannot be reached any more memory leak. The code compiles without error (C lets a void* be used as an int* without a cast).
Answer: compiles successfully but execution may result in memory leak
Answer: compiles successfully but execution may result in memory leak
Consider a TCP client and a TCP server running on two different machines. After completing data transfer, the TCP client calls close to terminate the connection and a FIN segment is sent to the TCP server. Server-side TCP responds by sending an ACK which is received by the client-side TCP. As per the TCP connections state diagram (RFC 793), in which state does the client-side TCP connection wait for the FIN from the sever-side TCP?
Answer: (D)
The client sends its FIN and moves to FIN-WAIT-1. Once the ACK for that FIN is received, it moves to FIN-WAIT-2. In this state it waits for the FIN from the server.
Answer: FIN-WAIT-2
Answer: FIN-WAIT-2
A sender S sends a message m to receiver R, which is digitally signed by S with its private key. In this scenario, one or more of the following security violations can take place.
I. S can launch a birthday attack to replace m with a fraudulent message.
II. A third party attacker can launch a birthday attack to replace m with a fraudulent message.
III. R can launch a birthday attack to replace m with a fraudulent message.
Which of the following are possible security violations?
I. S can launch a birthday attack to replace m with a fraudulent message.
II. A third party attacker can launch a birthday attack to replace m with a fraudulent message.
III. R can launch a birthday attack to replace m with a fraudulent message.
Which of the following are possible security violations?
Answer: (B)
A birthday attack looks for two different messages that have the same hash. Only the signer S can make use of it. S signs a harmless message, and later says the signature was made for the other message with the same hash. A third party or R cannot produce S's signature on a new hash.
Answer: I only
Answer: I only