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 6–10 of 68

Q6GATE 2024 (Session 1)1 markMCQ−0.33 if wrong
Consider the following C program:

#include <stdio.h>
void fX();
int main(){
fX();
return 0;}

void fX(){
char a;
if((a=getchar()) != '\n')
fX();
if(a != '\n')
putchar(a);}
Assume that the input to the program from the command line is 1234 followed by a newline character. Which one of the following statements is CORRECT?

Q7GATE 2024 (Session 2)1 markMCQ−0.33 if wrong
Consider the following C program. Assume parameters to a function are evaluated from right to left.

#include <stdio.h>
int g(int p) { printf("%d", p); return p; }
int h(int q) { printf("%d", q); return q; }
void f(int x, int y) {
g(x);
h(y);
}
int main() {
f(g(10),h(20));
}
Which one of the following options is the CORRECT output of the above C program?

Q8GATE 20231 markNAT
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;
}

Q9GATE 20232 marksMCQ−0.67 if wrong
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?
main f1 f2 f3 f3 f2 f3 f1 (A) main f1 f2 f3 f1 (C) main f1 f2 f3 f3 f1 (B) main f1 f2 f3 f3 f2 f1 (D)

Q10GATE 2021 (Session 1)2 marksNAT
Consider the following ANSI C function:
 int SimpleFunction(int Y[], int n, int x)
{
int total = Y[0], loopIndex;
for (loopIndex=1; loopIndex<=n-1; loopIndex++)
    total=x*total +Y[loopIndex];
return total;
}
Let Z be an array of 10 elements with Z[i]=1, for all i such that 0≤i≤90\leq i \leq 9. The value returned by SimpleFunction(Z,10,2) is __________

Keep practising

Topics in Programming in C

All CS topics ›