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 21–25 of 68

Q21GATE 2017 (Session 1)2 marksMCQ−0.67 if wrong
Consider the C functions foo and bar given below:
int foo (int val ) {
    int x = 0;
    while (val > 0) {
    x = x + foo(val--);
}
   return val ;
}
int bar (int val ) {
int x = 0;
while (val > 0) {
    x = x + bar(val-1);}
    return val ;
}
Invocations of foo(3) and bar(3) will result in:

Q22GATE 2017 (Session 1)2 marksNAT
The output of executing the following C program is ________.
 #include <stdio.h>
int total (int v) {
    static int count = 0;
    while (v) {
        count += v & 1;
        v >>= 1;
    }
    return count;
 }
void main ( ) {
static int x = 0;
int i = 5;
for (; i> 0; i--) {
x=x + total (i) ; 
}
printf ("%d\n", x) ; } 

Q23GATE 2016 (Session 1)1 markMCQ−0.33 if wrong
Consider the following C program.
 void f(int,short);
void main()
{
int i=100;
short s=12;
short *p=&s;
__________ ;//calltof()
} 
Which one of the following expressions, when placed in the blank above, will NOT result in a typec hecking error?

Q24GATE 2016 (Session 1)2 marksMCQ−0.67 if wrong
What will be the output of the following C program?

void count(int n){
   static int d=1;
   printf("%d ",n);
   printf("%d ",d);
   d++;
   if(n>1) count(n-1);
   printf("%d ",d);
}
void main(){
    count(3);
}

Q25GATE 2016 (Session 1)2 marksMCQ−0.67 if wrong
What will be the output of the following pseudo-code when parameters are passed by reference and dynamic scoping is assumed?

a=3;
void n(x){x=x*a;  print(x);}
void m(y){a=1;a=y-a;n(a);print(a);}
void main(){m(a);}

Keep practising

Topics in Programming in C

All CS topics ›