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 31–35 of 68

Q31GATE 2015 (Session 3)2 marksNAT
Suppose c=(c[0],...,c[k-1]) is an array of length k, where all the entries are from the set {0,1}. For any positive integers a and n, consider the following pseudocode.
DOSOMETHING(c, a, n)
z ← 1
for i ← 0 to k − 1
    do z ← z² mod n
     if c[i] = 1
         then z ← (z × a) mod n
return z

If k=4, c=(1,0,1,1), a=2 and n=8, then the output of DOSOMETHING(c,a,n) is _____.

Q32GATE 2014 (Session 2)1 markNAT
Consider the function func shown below:
 int func(int num) {
int count = 0;
while (num) {
    count++;
    num >>= 1;
}
return (count);
} 
The value returned by func(435)is __________.

Q33GATE 2014 (Session 2)2 marksNAT
Consider the following function
 double f (double x) {
if ( abs (x*x - 3) < 0.01) return x;
else return f (x / 2 + 1.5/x);
} 
Give a value q (to 2 decimals) such that f(q) will return q:______

Q34GATE 2014 (Session 2)2 marksMCQ−0.67 if wrong
Consider the C function given below
 int f(int j)
{
static int i = 50;
int k;
if (i == j)
{
printf("something");
k = f(i);
return 0;
}
else return 0;
} 
Which one of the following is TRUE?

Q35GATE 20132 marksMCQ−0.67 if wrong
What is the return value of f(p,p), if the value of p is initialized to 5 before the call? Note that the first parameter is passed by reference, whereas the second parameter is passed by value.
 int f (int &x, int c) {
  c = c - 1;
  if (c==0) return 1;
   x = x + 1;
return f(x,c) * x;
} 

Keep practising

Topics in Programming in C

All CS topics ›