C Programming


Question 1
Consider the following program:

int main()
{
  f1();
  f2(2);
  f3();
  return(0);
}

int f1()
{
  return(1);
}

int f2(int X)
{
  f3();
  if (X==1)
     return f1();
  else
     return (X*f2(X-1));
}

int f3()
{
  return(5);
}


Which one of the following options represents the activation tree corresponding to the main function?

A
A
B
B
C
C
D
D
GATE CSE 2023      Functions
Question 2
The integer value printed by the ANSI-C program given below is ______.
#include < stdio.h >
int funcp(){
   static int x = 1;
   x++;
   return x;
}
int main(){
   int x,y;
   x = funcp();
   y = funcp()+x;
   printf("%d\n", (x+y));
   return 0;
}
A
2
B
5
C
7
D
9
GATE CSE 2023      Functions


Question 3
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 4
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 5
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




There are 5 questions to complete.

2 thoughts on “C Programming”

  1. Question 124
    #include

    void f(int *p, int *q) {
    p=q;
    *p=2;
    }

    int i=0, j=1;

    int main() {
    f(&i, &j);
    printf(“%d %d\n”, i,j);
    return 0;
    }

    Reply

Leave a Comment