Function: GATE CS Previous Year Questions

Function · Programming in C

68 questions · asked in 26 of 27 years (2000–2026)

MCQ 47 · NAT 211-mark 35 · 2-mark 33

2000Questions per year2026

Questions 36–40 of 68

Q36GATE 20122 marksMCQ−0.67 if wrong
Consider the following C code segment.

int a, b, c = 0;
void prtFun(void);
main( )
{ static int a = 1; /* Line 1 */
   prtFun( );
   a += 1;
   prtFun( );
   printf(" \n %d %d ", a, b);
}
void prtFun(void)
{ static int a = 2; /* Line 2 */
   int b = 1;
   a += ++b;
   printf(" \n %d %d ", a, b);
}
What output will be generated by the given code segment if:

Line 1 is replaced by auto int a = 1;
Line 2 is replaced by register int a = 2;

Q37GATE 20122 marksMCQ−0.67 if wrong
Consider the following C code segment.

int a, b, c = 0;
void prtFun(void);
main( )
{ static int a = 1; /* Line 1 */
   prtFun( );
   a += 1;
   prtFun( );
   printf(" \n %d %d ", a, b);
}
void prtFun(void)
{ static int a = 2; /* Line 2 */
   int b = 1;
   a += ++b;
   printf(" \n %d %d ", a, b);
}
What output will be generated by the given code segment?

Q38GATE 20112 marksMCQ−0.67 if wrong
Consider the following recursive C function that takes two arguments
 unsigned int foo(unsigned int n, unsigned int r) {
  if (n  > 0) return (n%r +  foo (n/r, r ));
  else return 0;
}
What is the return value of the function foo when it is called as foo (513, 2)?

Q39GATE 20112 marksMCQ−0.67 if wrong
Consider the following recursive C function that takes two arguments
 unsigned int foo(unsigned int n, unsigned int r) {
  if (n  > 0) return (n%r +  foo (n/r, r ));
  else return 0;
}

What is the return value of the function foo when it is called as foo (345, 10) ?

Q40GATE 20102 marksMCQ−0.67 if wrong
What is the value printed by the following C program?
 #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));
    return 0;
} 

Keep practising

Topics in Programming in C

All CS topics ›