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 16–20 of 68

Q16GATE 20192 marksMCQ−0.67 if wrong
Consider the following C program:

void convert(int n) {
  if (n<0)
    printf("%d",n);
  else {
    convert(n/2);
    printf("%d",n%2);
  }
}
Which one of the following will happen when the function convert is called with any positive integer n as argument?

Q17GATE 20192 marksMCQ−0.67 if wrong
Consider the following C program:

#include <stdio.h>
int r(){
 int static num=7;
 return num--;
}
int main() {
 for(r();r();r()) {
  printf("%d ",r());
  };
 return 0;
}
Which one of the following values will be displayed on execution of the programs?

Q18GATE 20181 markNAT
Consider the following C program:
  #include <stdio.h>
int counter = 0;
int calc (int a, int b) {
    int c;
    counter++;
    if (b==3) return (a*a*a);
    else {
       c = calc(a, b/3);
       return (c*c*c);
           }
}
int main (){
calc(4, 81);
printf ("%d", counter);
}
The output of this program is _____.

Q19GATE 20182 marksNAT
Consider the following program written in pseudo-code. Assume that x and y are integers.

Count(x,y) {
     if (y != 1){
        if (x != 1) {
                  print("*");
                  Count(x/2, y);
                  }
            else {
                     y = y-1;
                    Count(1024, y);
                  }
      }
} 
The number of times that the print statement is executed by the call Count(1024,1024) is _____.

Q20GATE 2017 (Session 1)2 marksMCQ−0.67 if wrong
Consider the following two functions.
void fun1(int n) {
    if(n == 0) return;
    printf("%d", n);
    fun2(n - 2);
    printf("%d", n);
}
void fun2(int n) {
    if(n == 0) return;
    printf("%d", n);
    fun1(++n);
    printf("%d", n);
}
The output printed when fun1(5) is called is

Keep practising

Topics in Programming in C

All CS topics ›