C Programming

Question 1
What is printed by the following ANSI C program?
#include < stdio.h >
int main(int argc, char *argv[]){ 
 char a = 'P';
 char b = 'x';
 char c = (a  &  b) + '*';
 char d = (a | b) - '-';
 char e = (a ^ b) + '+'; 
 printf("%c %c %c \n", c, d, e); 
 return 0;
}

ASCII encoding for relevant characters is given below

A
z K S
B
122 75 83
C
* - +
D
P x +
GATE CSE 2022      Arithmetic Operation
Question 2
What is printed by the following ANSI C program?
#include < stdio.h >
int main(int argc, char *argv[])
{
 int a[3][3][3] =
 {{1, 2, 3, 4, 5, 6, 7, 8, 9},
 {10, 11, 12, 13, 14, 15, 16, 17, 18},
 {19, 20, 21, 22, 23, 24, 25, 26, 27}};
int i = 0, j = 0, k = 0; 
for( i = 0; i < 3; i++ ){

     for(k = 0; k < 3; k++ ) 
      printf("%d ", a[i][j][k]);
 printf(" \n");
}
return 0;
}
A
1 2 3
10 11 12
19 20 21
B
1 4 7
10 13 16
19 22 25
C
1 2 3
4 5 6
7 8 9
D
1 2 3
13 14 15
25 26 27
GATE CSE 2022      Array and Pointer
Question 3
What is printed by the following ANSI C program?

#include < stdio.h >
int main(int argc, char *argv[])
{
int x = 1, z[2] = {10, 11};
int *p=NULL; p=&x;
*p=10;
p =&z[1];
*(&z[0]+1)+=3;
printf("%d, %d, %d \n",x,z[0],z[1]); return   0;
}
A
1, 10, 11
B
1, 10, 14
C
10, 14, 11
D
10, 10, 14
GATE CSE 2022      Array and Pointer
Question 4
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 5
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 6
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 7
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 8
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 9
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 10
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


There are 10 questions to complete.

Leave a Comment