Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages
Filter by Categories
nmims post
Objective Type Set
Online MCQ Assignment
Question Solution
Solved Question
Uncategorized

1. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int mul(int a, int b, int c)
  3.     {
  4.         return a * b * c;
  5.     }
  6.     void main()
  7.     {
  8.         int *function_pointer;
  9.         function_pointer = mul;
  10.         printf("The product of three numbers is:%d",
  11.         function_pointer(2, 3, 4));
  12.     }

a) The product of three numbers is:24
b) Compile time error
c) Nothing
d) Varies

View Answer

Answer: b [Reason:] None.

2. What is the output of this C code?

  1.     #include <stdio.h>
  2.     int sub(int a, int b, int c)
  3.     {
  4.         return a - b - c;
  5.     }
  6.     void main()
  7.     {
  8.         int (*function_pointer)(int, int, int);
  9.         function_pointer = &sub;
  10.         printf("The difference of three numbers is:%d",
  11.         (*function_pointer)(2, 3, 4));
  12.     }

a) The difference of three numbers is:1
b) Run time error
c) The difference of three numbers is:-5
d) Varies

View Answer

Answer: c [Reason:] None.

3. One of the uses for function pointers in C is
a) Nothing
b) There are no function pointers in c
c) To invoke a function
d) To call a function defined at run-time.

View Answer

Answer: d [Reason:] None.

4. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void f(int);
  3.     void (*foo)() = f;
  4.     int main(int argc, char *argv[])
  5.     {
  6.         foo(10);
  7.         return 0;
  8.     }
  9.     void f(int i)
  10.     {
  11.         printf("%dn", i);
  12.     }

a) Compile time error
b) 10
c) Undefined behaviour
d) None of the mentioned

View Answer

Answer: b [Reason:] None.

5. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void f(int);
  3.     void (*foo)(void) = f;
  4.     int main(int argc, char *argv[])
  5.     {
  6.         foo(10);
  7.         return 0;
  8.     }
  9.     void f(int i)
  10.     {
  11.         printf("%dn", i);
  12.     }

a) Compile time error
b) 10
c) Undefined behaviour
d) None of the mentioned

View Answer

Answer: a [Reason:] None.

6. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void f(int);
  3.     void (*foo)(float) = f;
  4.     int main()
  5.     {
  6.         foo(10);
  7.     }
  8.     void f(int i)
  9.     {
  10.         printf("%dn", i);
  11.     }

a) Compile time error
b) 10
c) 10.000000
d) Undefined behaviour

View Answer

Answer: d [Reason:] None.

7. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void f(int (*x)(int));
  3.     int myfoo(int i);
  4.     int (*foo)(int) = myfoo;
  5.     int main()
  6.     {
  7.         f(foo(10));
  8.     }
  9.     void f(int (*i)(int))
  10.     {
  11.         i(11);
  12.     }
  13.     int myfoo(int i)
  14.     {
  15.         printf("%dn", i);
  16.         return i;
  17.     }

a) Compile time error
b) Undefined behaviour
c) 10 11
d) 10 Segmentation fault

View Answer

Answer: d [Reason:] None.

8. What is the output of this C code?

  1.     #include <stdio.h>
  2.     void f(int (*x)(int));
  3.     int myfoo(int);
  4.     int (*foo)() = myfoo;
  5.     int main()
  6.     {
  7.         f(foo);
  8.     }
  9.     void f(int(*i)(int ))
  10.     {
  11.         i(11);
  12.     }
  13.     int myfoo(int i)
  14.     {
  15.         printf("%dn", i);
  16.         return i;
  17.     }

a) 10 11
b) 11
c) 10
d) Undefined behaviour

View Answer

Answer: b [Reason:] None.