C Programming

Question 1
Consider the following ANSI C program
 #include < stdio.h >
int foo(int x, int y, int q) 
    {
        if ((x < = 0) && (y < = 0))
        return q;
        if (x < = 0)
        return foo(x, y-q, q);
        if (y < = 0)
        return foo(x-q, y, q);
        return foo(x, y-q, q) + foo(x-q, y, q);
    }
int main( )
{
    int r = foo(15, 15, 10);
    printf("%d", r);
    return 0;
}
The output of the program upon execution is ____
A
10
B
60
C
180
D
220
GATE CSE 2021 SET-2      Function
Question 2
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:
A
403 and 102
B
203 and 2
C
303 and 102
D
303 and 2
GATE CSE 2021 SET-2      Array and Pointer
Question 3
Consider the following ANSI C function:
int SomeFunction (int x, int y)
{
    if ((x==1) || (y==1)) return 1;
    if (x==y) return x;
    if (x > y) return SomeFunction(x-y, y);
    if (y > x) return SomeFunction (x, y-x);
 
} 
The value returned by SomeFunction(15, 255) is __________
A
17
B
15
C
255
D
5
GATE CSE 2021 SET-2      Function
Question 4
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?
A
14
B
20
C
24
D
30
GATE CSE 2021 SET-2      Array and Pointer
Question 5
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];
return total;
}
Let Z be an array of 10 elements with Z[i]=1, for all i such that 0\leq i \leq 9. The value returned by SimpleFunction(Z,10,2) is __________
A
1023
B
511
C
255
D
2047
GATE CSE 2021 SET-1      Function
Question 6
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 not compile successfully
B
The program will compile successfully and output 10 when executed
C
The program will compile successfully and output 8 when executed
D
The program will compile successfully and output 13 when executed
GATE CSE 2021 SET-1      Conditional Statement
Question 7
In the following procedure
 Integer procedure P(X,Y);
Integer X,Y;
value x;
begin
      K=5;
      L=8;
      P=x+y;
end
X is called by value and Y is called by name. If the procedure were invoked by the following program fragment
 K=0;
L=0;
Z=P(K,L);
then the value of Z will be set equal to
A
5
B
8
C
13
D
0
ISRO CSE 2020      Function
Question 8
Following declaration of an array of struct, assumes size of byte, short, int and long are 1,2,3 and 4 respectively. Alignment rule stipulates that n byte field must be located at an address divisible by n, the fields in the struct are not rearranged, padding is used to ensure alignment. All elements of array should be of same size.
 Struct complx
       Short s
       Byte b
       Long l
       Int i
End Complx
Complx C[10]
Assuming C is located at an address divisble by 8, what is the total size of C, in bytes?
A
150
B
160
C
200
D
240
ISRO CSE 2020      Array and Pointer
Question 8 Explanation: 
NOTE: This question is Excluded for evaluation.
Click here for detail solution by gateoverflow
Question 9
What is the output in a 32 bit machine with 32 bit compiler?
 #include < stdio.h >
rer(int **ptr2, int **ptr1)
{
    int *ii;
    ii=*ptr2;
    *ptr2=*ptr1;
    *ptr1=ii;
    **ptr1*=**ptr2;
    **ptr2+=**ptr1;
}
void main(){
    int var1=5, var2=10;
    int *ptr1=&var1,*ptr2=&var2;
    rer(&ptr1,&ptr2);
    printf("%d %d",var2,var1);
}
A
60,70
B
50,50
C
50,60
D
60,50
ISRO CSE 2020      Function
Question 10
What is output of the following 'C' code assuming it runs on a byte addressed little endian machine?
 #include < stdio.h >
int main()
{
    int x;
    char *ptr;
    x=622,100,101;
    printf("%d",(*(char *)&x)*(x%3));
    return 0;
}
A
622
B
311
C
22
D
110
ISRO CSE 2020      Array and Pointer


There are 10 questions to complete.

Leave a Comment

Like this FREE website? Please share it among all your friends and join the campaign of FREE Education to ALL.