C-Programming |Gate-2015| Previous Year Questions| Set-5

Set-15 C-Programming Gate 2005

C-Programming |Gate-2015|

1. The output of the following C program is __________. [GATE – 2015]

void f1 (int a, int b)
{
  int c;
  c=a; a=b; b=c;
}
void f2 (int *a, int *b)
{
  int c;
  c=*a; *a=*b;*b=c;
}
int main()
{
  int a=4, b=5, c=6;
  f1(a, b);
  f2(&b, &c);
  printf (“%d”, c-a-b);
  return 0;
}

a. -5
b. 6
c. 7
d. 8

Answer : a)


2. What is the output of the following C code? Assume that the address of x is 2000 (in decimal) and an integer requires four bytes of memory. [GATE – 2015]

#include <stdio.h>
int main()
{
   unsigned int x[4][3] = {{1, 2, 3}, {4, 5, 6},
                           {7, 8, 9}, {10, 11, 12}};
   printf(“%u, %u, %u”, x+3, *(x+3), *(x+2)+3);
}

a. 2036, 2036, 2036
b. 2012, 4, 2204
c. 2036, 10, 10
d. 2012, 4, 6

Answer : a)


3. Consider the following pseudo code, where x and y are positive integers. [GATE – 2015]

begin
   q := 0
   r := x
while r >= y do
   begin
      r := r – y
      q := q + 1
   end
end

The post condition that needs to be satisfied after the program terminates is  

a. {r = qx+y ∧ r
b. {x = qy+r ∧ r
c. {y = qx+r ∧ 0
d. {q+10}

Answer : b)


4. Consider the following C program segment. [GATE – 2015]

while (first <= last
{
   if (array [middle] < search)
      first = middle +1;
   else if (array [middle] == search)
      found = True;
   else last = middle – 1;
   middle = (first + last)/2;
}
if (first < last) not Present = True;

The cyclomatic complexity of the program segment is __________.

a. 5
b. 6
c. 7
d. 8

Answer : a)


5. Consider the following C function. [GATE – 2015]

int fun1 (int n)
{
   int i, j, k, p, q = 0;
   for (i = 1; i<n; ++i)
   {
      p = 0;
     for (j = n; j > 1; j = j/2)
         ++p;
      for (k = 1; k < p; k = k*2)
         ++q;
   }
   return q;
}

a. n3
b. n(log n)2
c. nlog n
d. nlog (log n)

Answer : d)


6. void foo(char *a)

{
if(*a && *a!= ‘ ’)
{
foo(a+1);
putchar(*a);
}
}

The output of the above function on input “ABCD EFGH” is :

Consider the following function  written C programming language: [GATE – 2015]

a. ABCD EFGH
b. ABCD
c. HGFE DCBA
d. DCBA

Answer : d)


7. int fun (int n)

{
int x=1, k;
if(n = =1) return x;
for  (k=1;k<n;++k)
x= x+fun (k)*fun (n-k);
return x;
}

The return value of fun (5) is________.

Consider the following C Functions. [GATE – 2015]

a. 51
b. 52
c. 53
d. 54

Answer : b)


8.  

Consider the C program below. The value printed by the above program is _______________   [GATE – 2015]

a. -2
b. 2
c. -1
d. 15

Answer : d)


9. Consider the following C program segment. [GATE – 2015]

# include <stdio.h>
int main( )
{
    char s1[7] = "1234", *p;
    p = s1 + 2;
    *p = '0' ;
printf ("%s", s1);

What will be printed by the program?

a. 12
b. 120400
c. 1204
d. 1034

Answer: c)


10. Consider the following recursive C function. If get(6) function is being called in main() then how many times will the get() function be invoked before returning to the main()?[GATE – 2015]

void get (int n)
{
   if (n < 1) return;
   get(n-1);
   get(n-3);
   printf("%d", n);
}

a. 15
b. 25
c. 35
d. 45

Answer: b)
C-Programming |Gate-2015|


11. Consider the following C program. [GATE – 2015]

# include
int main( )
{
  static int a[] = {10, 20, 30, 40, 50};
  static int *p[] = {a, a+3, a+4, a+1, a+2};
  int **ptr = p;
  ptr++;
  printf("%d%d", ptr - p, **ptr};
}

The output of the program is _________

a. 140
b. 150
c. 160
d. 170

Answer : a)


12.  Consider the following C program: [GATE – 2015]

# include <stdio.h>
int main( )
{
   int i, j, k = 0;
   j = 2 * 3 / 4 + 2.0 / 5 + 8 / 5;
   k  -= --j;
   for (i = 0; i < 5; i++)
   {
      switch(i + k)
      {
         case 1:
         case 2: printf("n%d", i + k);
         case 3: printf("n%d", i + k);
         default: printf("n%d", i + k);
      }
   }
   return 0;
}

a. 10
b. 11
c. 12
d. 13

Answer :  a)
C-Programming |Gate-2015|


13. Consider the following C program. The output of the program is __________. [GATE – 2015]

# include <stdio.h>
int f1(void);
int f2(void);
int f3(void);
int x = 10;
int main()
{
    int x = 1;
    x += f1() + f2() + f3() + f2();
    pirntf("%d", x);
    return 0;
}
int f1()
{
    int x = 25;
    x++;
    return x;
}
int f2( )
{
    static int x = 50;
    x++;
    return x;
}
int f3( )
{
    x *= 10;
    return x;
}

a. 230
b. 240
c. 250
d. 260

Answer : a)


Back to GATE-HOME


Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *