• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

C Functions

Question 11

Consider the following C-program: C
double foo (double); /* Line 1 */

int main()
{

    double da, db;

    // input da

    db = foo(da);

}

double foo(double a)
{
    return a;
}
The above code compiled without any error or warning. If Line 1 is deleted, the above code will show:
  • no compile warning or error
  • some compiler-warnings not leading to unintended results
  • some compiler-warnings due to type-mismatch eventually leading to unintended results
  • compiler errors

Question 12

Consider the following C function

C
void swap (int a, int b)
{
   int temp;
   temp = a;
   a = b;
   b = temp;
}

In order to exchange the values of two variables x and y.

  • Call swap (x, y)

  • Call swap (&x, &y)

  • swap(x,y) cannot be used as it does not return any value

  • swap(x,y) cannot be used as the parameters are passed by value

Question 13

The value of j at the end of the execution of the following C program. C
int incr(int i)
{
   static int count = 0;
   count = count + i;
   return (count);
}
main()
{
   int i,j;
   for (i = 0; i <=4; i++)
      j = incr(i);
}
  • 10
  • 4
  • 6
  • 7

Question 14

The output of the following C program is __________. C
void f1 (int a, int b)
{
  int c;
  c=a; a=b; b=c;
}
void f2 (int *a, int *b)
{
  int c;
  c=*a; *a=*b;*b=c;
}
int main()
{
  int a=4, b=5, c=6;
  f1(a, b);
  f2(&b, &c);
  printf (%d, c-a-b);
  return 0;
}
  • -5
  • -4
  • 5
  • 3

Question 15

What’s going to happen when we compile and run the following C program snippet? C
#include \"stdio.h\"
int main()
{
 int a = 10;
 int b = 15;

 printf(\"=%d\",(a+1),(b=a+2));
 printf(\" %d=\",b);

 return 0;
}
  • =11 15=
  • =11 12=
  • Compiler Error due to (b=a+2) in the first printf().
  • No compile error but output would be =11 X= where X would depend on compiler implementation.

Question 16

What’s going to happen when we compile and run the following C program snippet? C
#include \"stdio.h\"
int main()
{
 int a = 10;

 printf(\"=%d %d=\",(a+1));

 return 0;
}
  • =11 0=
  • =11 X= where X would depend on Compiler implementation
  • Undefined behavior
  • Compiler Error due to missing argument for second %d

Question 17

Both of the following declarations for function pointers are equivalent. Second one (i.e. with typedef) looks cleaner. C
/* First Declaration */
int (*funPtr1)(int), (*funPtr2)(int);

/* Second Declaration*/
typedef int (*funPtr)(int);
funPtr funPtr1, funPtr2;
  • TRUE
  • FALSE

Question 18

Pick the best statement for the following program. C
#include \"stdio.h\"

int foo(int a)
{
 printf(\"%d\",a);
 return 0;
}

int main()
{
 foo;
 return 0;
}
  • It’ll result in compile error because foo is used without parentheses.
  • No compile error and some garbage value would be passed to foo function. This would make foo to be executed with output “garbage integer”.
  • No compile error but foo function wouldn’t be executed. The program wouldn\'t print anything.
  • No compile error and ZERO (i.e. 0) would be passed to foo function. This would make foo to be executed with output 0.

Question 19

What is the output of the following program? C
#include <stdio.h>
int funcf (int x);
int funcg (int y);

main()
{
    int x = 5, y = 10, count;
    for (count = 1; count <= 2; ++count)
    {
        y += funcf(x) + funcg(x);
        printf (\"%d \", y);
    }
}

funcf(int x)
{
    int y;
    y = funcg(x);
    return (y);
}

funcg(int x)
{
    static int y = 10;
    y += 1;
    return (y+x);
}
  • 43 80
  • 42 74
  • 33 37
  • 32 32

Question 20

What is the output printed by the following program? C
#include<stdio.h>
int f(int n, int k)
{
    if (n == 0)
        return 0;
    else if (n % 2)
        return f(n/2, 2*k) + k;
    else return f(n/2, 2*k) - k;
}
int main ()
{
    printf(\"%d\", f(20, 1));
    return 0;
}
  • 5
  • 8
  • 9
  • 20

There are 41 questions to complete.

Last Updated :
Take a part in the ongoing discussion