GATE 2012
82 questions
MCQ 821-mark 39 · 2-mark 43
Questions 26–30 of 82
Register renaming is done in pipelined processors
Answer: (C)
In register renaming, each new use of a register name gets a fresh physical register. This removes WAR and WAW hazards, which are false dependency hazards.
Answer: to handle certain kinds of hazards
Answer: to handle certain kinds of hazards
What will be the output of the following C program segment?
char inChar = 'A' ;
switch ( inChar ) {
case 'A' : printf ("Choice A\n") ;
case 'B' :
case 'C' : printf ("Choice B") ;
case 'D' :
case 'E' :
default : printf ( " No Choice" ) ; } Answer: (C)
No break statement is present, so control falls through from case 'A' into every case after it.
The program prints "Choice A" and a newline, then "Choice B", then " No Choice".
Answer: Choice A / Choice B No Choice
The program prints "Choice A" and a newline, then "Choice B", then " No Choice".
Answer: Choice A / Choice B No Choice
Consider the following C code segment.
Line 1 is replaced by auto int a = 1;
Line 2 is replaced by register int a = 2;
int a, b, c = 0;
void prtFun(void);
main( )
{ static int a = 1; /* Line 1 */
prtFun( );
a += 1;
prtFun( );
printf(" \n %d %d ", a, b);
}
void prtFun(void)
{ static int a = 2; /* Line 2 */
int b = 1;
a += ++b;
printf(" \n %d %d ", a, b);
}What output will be generated by the given code segment if: Line 1 is replaced by auto int a = 1;
Line 2 is replaced by register int a = 2;
Answer: (D)
Now the variable a in prtFun is a register (automatic) variable. It is set to 2 again on every call.
- Every call: a = 2 + 2 = 4 and b = 2 so it prints 4 2 two times.
- In main: the local a = 1 + 1 = 2 and the global b = 0 so it prints 2 0.
Answer: 4 2, 4 2, 2 0
- Every call: a = 2 + 2 = 4 and b = 2 so it prints 4 2 two times.
- In main: the local a = 1 + 1 = 2 and the global b = 0 so it prints 2 0.
Answer: 4 2, 4 2, 2 0
Consider the following C code segment.
int a, b, c = 0;
void prtFun(void);
main( )
{ static int a = 1; /* Line 1 */
prtFun( );
a += 1;
prtFun( );
printf(" \n %d %d ", a, b);
}
void prtFun(void)
{ static int a = 2; /* Line 2 */
int b = 1;
a += ++b;
printf(" \n %d %d ", a, b);
}What output will be generated by the given code segment?Answer: (C)
In prtFun, the static a starts at 2 and keeps its value between calls. The local b is set to 1 and becomes 2 on every call.
- First call: a = 2 + 2 = 4 the output is 4 2
- Second call: a = 4 + 2 = 6 the output is 6 2
- In main: its own static a = 1 + 1 = 2, and the global b = 0 the output is 2 0
Answer: 4 2, 6 2, 2 0
- First call: a = 2 + 2 = 4 the output is 4 2
- Second call: a = 4 + 2 = 6 the output is 6 2
- In main: its own static a = 1 + 1 = 2, and the global b = 0 the output is 2 0
Answer: 4 2, 6 2, 2 0
Suppose a circular queue of capacity (n-1) elements is implemented with an array of n elements. Assume that the insertion and deletion operations are carried out using REAR and FRONT as array index variables, respectively. Initially, REAR = FRONT = 0. The conditions to detect queue full and queue empty are
Answer: (A)
The queue always leaves one slot unused. This lets us tell a full queue from an empty one.
- Empty: REAR == FRONT
- Full: the next position of REAR would reach FRONT, so (REAR + 1) mod n == FRONT
Answer: full: (REAR+1) mod n == FRONT, empty: REAR == FRONT
- Empty: REAR == FRONT
- Full: the next position of REAR would reach FRONT, so (REAR + 1) mod n == FRONT
Answer: full: (REAR+1) mod n == FRONT, empty: REAR == FRONT