C-Programming |Gate-2010| previous year questions| Set-10

Set-15 C-Programming Gate 2005

C-Programming |Gate-2010|

1. What does the following program print? [GATE – 2010]

#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);  
 getchar();
  return 0;
}

a. 2 2
b. 2 1
c. 0 1
d. 0 2

Answer : d)


2. What is the value printed by the foloowing c program [GATE – 2010]

#include<stdio.h>
int f(int *a, int n)
{
  if(n <= 0) return 0;
  else if(*a % 2 == 0) return *a + f(a+1, n-1);
  else return *a - f(a+1, n-1);
}
int main()
{
  int a[] = {12, 7, 13, 4, 11, 6};
  printf("%d", f(a, 6));
  getchar();
  return 0;
}

a. -9
b. 5
c. 15
d. 19

Answer : c)


Back to GATE-HOME


Spread the love

Leave a Comment

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