• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

C Functions

Question 21

Consider the following C program. C
void f(int, short);
void main()
{
  int i = 100;
  short s = 12;
  short *p = &s;
  __________ ;   // call to f()
}
Which one of the following expressions, when placed in the blank above, will NOT result in a type checking error?
  • f(s, *s)
  • i = f(i,s)
  • f(i,*s)
  • f(i,*p)

Question 22

Consider the following program: C
int f(int *p, int n)
{
    if (n <= 1) return 0;
    else return max(f(p+1,n-1),p[0]-p[1]);
}
int main()
{
    int a[] = {3,5,2,6,4};
    printf(\"%d\", f(a,5));
}
Note: max(x,y) returns the maximum of x and y. The value printed by this program is
  • 2
  • 3
  • 4
  • 5

Question 23

Given a boolean function f (x1, x2, ..., xn), which of the following equations is NOT true  
  • f (x1, x2, ..., xn) = x1\'f(x1, x2, ..., xn) + x1f(x1, x2, ..., xn)
  • f (x1, x2, ..., xn) = x2f(x1, x2, …, xn) + x2\'f(x1, x2, …,xn)
  • f (x1, x2, ..., xn) = xn\'f(x1, x2, …, 0) + xnf(x1, x2, …,1)
  • f (x1, x2, ..., xn) = f(0, x2, …, xn) + f(1, x2, .., xn)

Question 24

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 _______ . Note -This was Numerical Type question.
  • 10230
  • 10
  • 1023
  • 23010

Question 25

Consider the function
int fun(x: integer)
{
If x > 100 then fun = x – 10;
else
fun = fun(fun(x + 11));
}
For the input x = 95, the function will return
  • 89
  • 90
  • 91
  • 92

Question 26

Consider the function
int func(int num) {
int count = 0;
while(num) {
count++;
num >>= 1;
}
return(count) ;
}
For func(435) the value returned is
  • 9
  • 8
  • 0
  • 10

Question 27

Consider the following C function
void swap ( int x, int y )
{
int tmp;
tmp = x;
x= y;
y = tmp;
}
In order to exchange the values of two variables a and b:
  • Call swap (a, b)
  • Call swap (&a, &b)
  • swap(a, b) cannot be used as it does not return any value
  • swap(a, b) cannot be used as the parameters passed by value

Question 28

Which of the following is/are side effects of scan conversion ? a. Aliasing b. Unequal intensity of diagonal lines c. Overstriking in photographic applications d. Local or Global aliasing
  • a and b
  • a, b and c
  • a, c and d
  • a, b, c and d

Question 29

Consider the following C code. #include
#include 
void main()
{
 double pi = 3.1415926535;
 int a = 1;
 int i;
 for(i=0; i < 3; i++)
 if(a = cos(pi * i/2) )
 printf("%d ",1);
 else printf("%d ", 0);
}
What would the program print?
  • 000
  • 010
  • 101
  • 111

Question 30

Consider the following C function:
int f(int n)
{
static int i = 1;
if(n >= 5) return n;
n = n+i;
i++;
return f(n);
}
The value returned by f(1) is
  • 5
  • 6
  • 7
  • 8

There are 41 questions to complete.

Last Updated :
Take a part in the ongoing discussion