1
GATE CSE 2024 Set 1
MCQ (More than One Correct Answer)
+2
-0.66

Consider the following C function definition.

int f(int x, int y) {
for (int i=0; i<y; i++) {
x=x+x+y;
}
return x;
}

Which of the following statements is/are TRUE about the above function?

A

If the inputs are x=20, y=10, then the return value is greater than 220

B

If the inputs are x=20, y=20, then the return value is greater than 220

C

If the inputs are x=20, y=10, then the return value is less than 210

D

If the inputs are x=10, y=20, then the return value is greater than 220

2
GATE CSE 2021 Set 1
+2
-0.67

Consider the following ANSI C program.

#include <stdio.h>

int main( ) {

int i, j, count;

count = 0;

i = 0;

for (j = -3; j <= 3; j++)  {

if ((j >= 0) && (i++))

count = count + j;

}

count = count + i;

printf("%d", count);

return 0;

}

Which one of the following options is correct?

A
The program will compile successfully and output 10 when executed.
B
The program will compile successfully and output 8 when executed.
C
The program will compile successfully and output 13 when executed.
D
The program will not compile successfully.
3
GATE CSE 2021 Set 1
Numerical
+2
-0.67

Consider the following ANSI C function:

int SimpleFunction (int y[], int n, int x)

{

int total = y[0], loopIndex;

for (loopIndex = 1; loopIndex <= n - 1; loopIndex++)

total = x * total + y[loopIndex];

}

Let Z be an array of 10 elements with Z[i] = 1, for all i such that 0 ≤ i ≤ 9. The value returned by SimpleFunction (Z, 10, 2) is ______

4
GATE CSE 2020
Numerical
+2
-0.67
Consider the following C functions.
int tob(int b, int* arr) {
int i;
for (i=0; b>0; i++) {
if (b%2) arr[i] = 1;
else arr[i]=0;
b = b/2;
}
return (i);
}

____________________
int pp(int a, int b) {
int arr[20];
int i, tot = 1, ex, len;
ex = a;
len = tob (b, arr);
for (i=0;  i < len; i++) {
if (arr[i] ==1)
tot = tot * ex;
ex = ex * ex;
}
return (tot);
}

The value returned by pp (3, 4) is ________.