VOOZH about

URL: https://www.geeksforgeeks.org/quizzes/loops-conditionals-gate-cs-pyq-quiz/

⇱ Quiz about Loops & Conditionals GATE CS PYQ Quiz


Last Updated :
Discuss
Comments

Question 1

Consider the following C program.

Which one of the following options is correct?

  • The program will not compile successfully

  • The program will compile successfully and output 10 when executed

  • The program will compile successfully and output 8 when executed

  • The program will compile successfully and output 13 when executed

Question 2

Consider the following ANSI C program.

#include < stdio.h >
int main( )
{
int arr[4][5];
int i, j;
for (i=0; i<4; i++)
{
for (j=0; j<5; j++)
{
arr[i][j] = 10 * i + j;
}
}
printf("%d", *(arr[1]+9));
return 0;
}

What is the output of the above program?

  • 14

  • 20

  • 24

  • 30

Question 3

Consider the following ANSI C code segment: 

z=x + 3 + y->f1 + y->f2; 
for (i = 0; i < 200; i = i + 2) 

if (z > i) 

p = p + x + 3; 
q = q + y->f1; 
} else 

p = p + y->f2; 
q = q + x + 3; 


Assume that the variable y points to a struct (allocated on the heap) containing two fields f1 and f2, and the local variables x, y, z, p, q, and i are allotted registers. Common sub-expression elimination (CSE) optimization is applied on the code. The number of addition and the dereference operations (of the form y ->f1 or y ->f2) in the optimized code, respectively, are:

  • 403 and 102

  • 203 and 2

  • 303 and 102

  • 303 and 2

Question 4

What will be the output of the following C program segment?

  • No choice
  • Choice A
  • Choice A
    Choice B No choice
  • Program gives no output as it is erroneous

Question 5

Consider the following C function.

Which one of the following is the time complexity for function fun1?

  • n3

  • n (logn)2

  • nlogn 

  • nlog(logn)

Question 6

Consider the following segment of C-code:

 int j, n;
j = 1;
while (j <= n)
j = j*2;

The number of comparisons made in the execution of the loop for any n > 0 is: Base of Log is 2 in all options.

  • CEIL(logn) + 2

  • n

  • CEIL(logn)

  • FLOOR(logn) + 2

Question 7

The following function computes the maximum value contained in an integer array p[] of size n (n >= 1) 

The missing loop condition is

  • a != n

  • b != 0

  • b > (a + 1)

  • b != a

Question 8

The following function computes X

Y

for positive integers X and Y.

Which one of the following conditions is TRUE before every iteration of the loop

👁 options1
  • A

  • B

  • C

  • D

Question 9

Consider the following C function in which size is the number of elements in the array E: The value returned by the function MyX is the

  • maximum possible sum of elements in any sub-array of array E.

  • maximum element in any sub-array of array E.

  • sum of the maximum elements in all possible sub-arrays of array E

  • the sum of all the elements in the array E.

Question 10

Consider the following program fragment for reversing the digits in a given integer to obtain a new integer. Let n = D1D2…Dm

int n, rev;
rev = 0;
while (n > 0)
{
rev = rev*10 + n%10;
n = n/10;
}

The loop invariant condition at the end of the ith iteration is:

  • n = D1D2….Dm-i and rev = DmDm-1…Dm-i+1

  • n = Dm-i+1…Dm-1Dm and rev = Dm-1….D2D1

  • n != rev

  • n = D1D2….Dm and rev = DmDm-1…D2D1

There are 27 questions to complete.

Take a part in the ongoing discussion