MCQs on Functions in C | C Programming

Functions in C are essential building blocks that allow you to break down complex programs into smaller, manageable tasks. Understanding MCQs on Functions in C helps you master function creation, calling, parameter passing, and recursion. These concepts are vital for improving coding skills and preparing for exams or interviews.

Function Definition and Declaration

  1. What is the correct way to declare a function in C?
    • a) int function_name();
    • b) function_name()
    • c) void function_name;
    • d) define function_name();
  2. Which keyword is used to return a value from a function?
    • a) break
    • b) continue
    • c) return
    • d) exit
  3. What is the term for a function that is defined but not called in a program?
    • a) Inline function
    • b) Static function
    • c) Global function
    • d) Unused function
  4. What is the return type of the main function in C?
    • a) void
    • b) char
    • c) int
    • d) float
  5. Which is the correct syntax for defining a function in C?
    • a) return_type function_name(parameters) { /* code */ }
    • b) function_name(parameters) { /* code */ }
    • c) int main(parameters) { /* code */ }
    • d) void function_name(parameters) /* code */

Function Parameters and Return Types

  1. What is a function prototype?
    • a) A complete function definition
    • b) A declaration of a function before its use
    • c) A function that returns void
    • d) A function with no parameters
  2. What is the correct way to pass parameters to a function by value?
    • a) Pass the address of the parameter
    • b) Pass the actual value of the parameter
    • c) Pass a pointer to the parameter
    • d) Both a and c
  3. What is the main difference between void and int return types?
    • a) void returns a value, while int does not
    • b) int returns an integer, while void returns nothing
    • c) Both return nothing
    • d) Both return an integer
  4. In C, what does a function return if the return type is not specified?
    • a) void
    • b) int
    • c) char
    • d) Undefined
  5. Which of the following functions has a return type of int and one int parameter?
    • a) int func(int x);
    • b) void func(int x);
    • c) int func(void);
    • d) float func(int x);

Scope and Lifetime of Variables (Local, Global, Static)

  1. Which variable is accessible throughout the program?
    • a) Local
    • b) Static
    • c) Global
    • d) Constant
  2. Where is a local variable declared?
    • a) Outside the main function
    • b) Inside a function or block
    • c) Anywhere in the code
    • d) None of the above
  3. Which keyword is used to declare a static variable?
    • a) static
    • b) const
    • c) volatile
    • d) extern
  4. What will happen to a local variable declared inside a function after the function call ends?
    • a) It is deleted
    • b) It remains in memory
    • c) It is converted to global
    • d) None of the above
  5. Which variable type retains its value even after a function call ends?
    • a) Global
    • b) Local
    • c) Static
    • d) Constant

Recursion

  1. What is recursion in C programming?
    • a) A function that calls itself
    • b) A loop that repeats
    • c) A function calling another function
    • d) A variable type
  2. What is the primary requirement for recursion to end?
    • a) Base condition
    • b) Loop condition
    • c) Infinite loop
    • d) Static condition
  3. Which of the following problems can be solved using recursion?
    • a) Factorial calculation
    • b) Fibonacci sequence
    • c) Tower of Hanoi
    • d) All of the above
  4. What will happen if a recursive function lacks a base condition?
    • a) It will cause a stack overflow
    • b) It will execute once
    • c) It will return NULL
    • d) It will return a random number
  5. Which function demonstrates a recursive call?
    • a) int f(int x) { return x + 1; }
    • b) void f() { printf("Hello"); }
    • c) int f(int x) { return f(x - 1); }
    • d) void f() { return; }

Inline Functions

  1. What is an inline function?
    • a) A function that can be defined within another function
    • b) A function that the compiler attempts to expand in place
    • c) A function that runs in the background
    • d) A function that requires static declaration
  2. What keyword is used to declare an inline function?
    • a) static
    • b) inline
    • c) extern
    • d) global
  3. Inline functions are typically used to:
    • a) Increase speed of execution by avoiding function calls
    • b) Reduce code size
    • c) Support recursion
    • d) None of the above
  4. Inline functions are not suitable for:
    • a) Simple mathematical operations
    • b) Large functions with complex logic
    • c) Functions with single lines of code
    • d) Frequently called functions
  5. Which function cannot be inlined by the compiler?
    • a) Simple functions with return statements
    • b) Recursive functions
    • c) Functions with only one line of code
    • d) None of the above

Library Functions (stdio.h, math.h, etc.)

  1. Which library is required to use printf and scanf?
    • a) math.h
    • b) stdio.h
    • c) string.h
    • d) stdlib.h
  2. The sqrt function is available in which library?
    • a) stdio.h
    • b) string.h
    • c) math.h
    • d) stdlib.h
  3. Which function from math.h is used to calculate the power of a number?
    • a) sqrt()
    • b) pow()
    • c) exp()
    • d) log()
  4. Which library function is used to allocate memory?
    • a) malloc()
    • b) printf()
    • c) strcpy()
    • d) scanf()
  5. Which library provides the function to find the absolute value of an integer?
    • a) stdio.h
    • b) stdlib.h
    • c) math.h
    • d) string.h

More Questions on Functions

  1. Which header file is required for file handling in C?
    • a) stdlib.h
    • b) math.h
    • c) stdio.h
    • d) string.h
  2. Which function is used to find the length of a string?
    • a) strlen()
    • b) strcpy()
    • c) strcat()
    • d) strstr()
  3. Which library function can be used to generate a random number?
    • a) rand()
    • b) random()
    • c) strcat()
    • d) sqrt()
  4. In which library can you find the ceil and floor functions?
    • a) stdio.h
    • b) math.h
    • c) stdlib.h
    • d) string.h
  5. Which function is used to get the cosine of an angle in radians?
    • a) cos()
    • b) sin()
    • c) tan()
    • d) log()
  6. Which library function returns a pointer to the first occurrence of a character in a string?
    • a) strstr()
    • b) strchr()
    • c) strrchr()
    • d) strcpy()
  7. Which header file is required for memory manipulation functions like memset and memcpy?
    • a) stdio.h
    • b) stdlib.h
    • c) string.h
    • d) math.h
  8. Which function reads a line of text and stores it in a character array?
    • a) printf()
    • b) fgets()
    • c) fputs()
    • d) strcpy()
  9. Which function compares two strings?
    • a) strcpy()
    • b) strcmp()
    • c) strcat()
    • d) strstr()
  10. Which function is used to terminate a program?
    • a) return()
    • b) break()
    • c) exit()
    • d) terminate()

General Questions on Function Usage

  1. Which of the following is a correct function prototype?
    • a) void f(int);
    • b) int f();
    • c) float f(char, int);
    • d) All of the above
  2. Which type of function does not return any value?
    • a) void
    • b) int
    • c) char
    • d) float
  3. Which function should you use to calculate e raised to a given power?
    • a) pow()
    • b) sqrt()
    • c) exp()
    • d) log()
  4. If a function takes no parameters, the parentheses are filled with:
    • a) void
    • b) empty
    • c) NULL
    • d) none
  5. In a recursive function, which of the following is essential?
    • a) if-else
    • b) base case
    • c) while loop
    • d) None of the above

46. Which function in math.h returns the remainder of a division operation?

  • a) remainder()
  • b) modf()
  • c) mod()
  • d) fmod()

47. Which type of variable retains its value between function calls?

  • a) Local variable
  • b) Global variable
  • c) Static variable
  • d) Dynamic variable

48. Which function would you use to get the square root of a number?

  • a) power()
  • b) sqrt()
  • c) log()
  • d) exp()

49. Which keyword is used to prevent a function from modifying a variable passed by reference?

  • a) final
  • b) static
  • c) const
  • d) readonly

50. What is the purpose of the void keyword in a function declaration?

  • a) To specify no return type
  • b) To specify the function returns an integer
  • c) To declare a global function
  • d) To allow multiple return values

Q.NoAnswer
1a) Function definition and declaration are necessary for function usage.
2c) The function prototype declares a function without defining it.
3d) Arguments are passed to functions in C by value.
4c) void is used to declare a function that returns no value.
5a) Local variables are accessible only within the function they are declared in.
6b) Global variables are accessible throughout the program.
7b) Local variables have automatic storage duration by default.
8b) Static variables retain their value between function calls.
9b) The lifetime of a static variable is the lifetime of the program.
10a) Recursion is when a function calls itself.
11c) Recursive functions must have a base case to stop recursion.
12b) Infinite recursion occurs when there’s no base case.
13a) inline suggests the compiler to insert the function’s code at each call site.
14a) Inline functions can be defined using the inline keyword.
15c) Inline functions can help reduce function call overhead.
16a) printf is a library function in stdio.h.
17a) sqrt is a function from math.h.
18d) The function pow() computes power.
19a) exit() function terminates the program.
20c) The main function is the entry point of a C program.
21b) int function return type signifies returning an integer value.
22b) The return statement is used to return a value from a function.
23a) scanf is used for input in C.
24b) void means the function has no parameters.
25b) Global variables are declared outside all functions.
26b) int, float, and double are standard data types in C.
27c) Constants are defined with #define or const.
28b) The scope of an identifier determines its visibility.
29a) register suggests storing a variable in a CPU register.
30b) extern is used to declare a global variable in another file.
31c) A function prototype is declared before calling the function.
32a) A function declaration specifies the function name and parameters.
33a) void means the function returns no value.
34b) Functions can have multiple parameters.
35a) Functions are defined with a return type, name, and parameters.
36b) Functions are called using the function name and arguments.
37c) string.h is required for memory manipulation functions like memset.
38b) fgets() reads a line of text and stores it in a character array.
39b) strcmp() compares two strings.
40c) exit() is used to terminate a program.
41d) All of the above are correct prototypes.
42a) void specifies a function with no return value.
43c) exp() calculates e raised to a given power.
44a) Use void for no parameters in a function.
45b) A recursive function needs a base case.
46d) fmod() returns the remainder of a division.
47c) Static variables retain their value between calls.
48b) sqrt() calculates the square root.
49c) const prevents modification of a variable.
50a) void specifies no return type for a function.

Use a Blank Sheet, Note your Answers and Finally tally with our answer at last. Give Yourself Score.

X
error: Content is protected !!
Scroll to Top