4.2 - function in C.


Back Button Home

4.2.1 - introduction to function, Definition and their Prototypes.


1. How are multidimensional arrays stored in memory?
  • (A) Row-major order
  • (B) Column-major order
  • (C) Random order
  • (D) They cannot be stored in memory
Correct Answer: (A) Row-major order
2. What is the basic type of multiple dimensions array in C?
  • (A) 2D array
  • (B) 3D array
  • (C) 1D array
  • (D) Array of pointers
Correct Answer: (A) 2D array
3. Which of the following is true about a 2D array in C?
  • (A) A distinct 1D array can represent each element
  • (B) Only one row can be declared
  • (C) Rows and columns must have the same size
  • (D) 2D arrays are only used for matrices
Correct Answer: (A) A distinct 1D array can represent each element
4. How many loops are needed to traverse a 2D array in C?
  • (A) 1
  • (B) 2
  • (C) 3
  • (D) 4
Correct Answer: (B) 2
5. Which matrix is called a rectangle matrix in a 2D array?
  • (A) When rows and columns are equal
  • (B) When rows are greater than columns
  • (C) When rows and columns differ
  • (D) When columns are greater than rows
Correct Answer: (C) When rows and columns differ
6. What is the valid declaration for a 2D array?
  • (A) int array[][];
  • (B) int array[3][];
  • (C) int array[3][4];
  • (D) int array[];
Correct Answer: (C) int array[3][4];
7. What is the default return type of a C function?
  • (A) int
  • (B) void
  • (C) float
  • (D) char
Correct Answer: (A) int
8. Which of the following does not return any value?
  • (A) Procedure
  • (B) Function
  • (C) main()
  • (D) None of the above
Correct Answer: (A) Procedure
9. What is stored in a stack before calling a function?
  • (A) Arguments
  • (B) Return address
  • (C) Local variables
  • (D) None of the above
Correct Answer: (B) Return address
10. Which of the following components form a function declaration?
  • (A) Return type, name, parameters
  • (B) Body of the function
  • (C) Only the name
  • (D) None of the above
Correct Answer: (A) Return type, name, parameters
11. What is the correct way to declare a 2D array without specifying the row size?
  • (A) int array[][3];
  • (B) int array[3][];
  • (C) int array[];
  • (D) int array[][];
Correct Answer: (A) int array[][3];
12. Which of the following will update an element in a 2D array?
  • (A) Modify the element directly
  • (B) Scan and replace via loops
  • (C) Insert at the new position
  • (D) None of the above
Correct Answer: (B) Scan and replace via loops
13. What is the advantage of using functions in C?
  • (A) Code duplication
  • (B) Efficient memory allocation
  • (C) Less readability
  • (D) Slower execution
Correct Answer: (B) Efficient memory allocation
14. Which function prototype is valid in C?
  • (A) int func();
  • (B) void func(int);
  • (C) float func(int, char);
  • (D) All of the above
Correct Answer: (D) All of the above
15. Which of the following allows functions to be reused in C?
  • (A) Procedures
  • (B) Subprograms
  • (C) Function calls
  • (D) Macros
Correct Answer: (C) Function calls
16. What is a key benefit of subprograms?
  • (A) Prevent code reuse
  • (B) Halts the main program
  • (C) Reduces code repetition
  • (D) Slows down execution
Correct Answer: (C) Reduces code repetition
17. Which of the following is incorrect about 2D array declaration?
  • (A) int arr[4][3];
  • (B) int array[][] = {1,2,3};
  • (C) int array[][3];
  • (D) int array[2][3];
Correct Answer: (B) int array[][] = {1,2,3};
18. Which operation is performed first when a function is called?
  • (A) Stack update
  • (B) Main function pauses
  • (C) Subprogram execution
  • (D) Return address stored
Correct Answer: (D) Return address stored
19. What is matrix multiplication in C?
  • (A) Adding corresponding elements
  • (B) Multiplying row of one matrix with column of another
  • (C) Transposing one matrix
  • (D) Copying elements
Correct Answer: (B) Multiplying row of one matrix with column of another
20. How many loops are needed for matrix multiplication?
  • (A) 1
  • (B) 2
  • (C) 3
  • (D) 4
Correct Answer: (C) 3

4.2.2 - Function Arguments and function Call.


21. What is the default return type for a function in C if not specified?
  • (A) int
  • (B) void
  • (C) float
  • (D) char
Correct Answer: (A) int
22. Which of the following is the correct syntax for declaring a function with an argument but no return type?
  • (A) int function(int x);
  • (B) void function(int x);
  • (C) float function(int x);
  • (D) char function(int x);
Correct Answer: (B) void function(int x);
23. Which of the following is true about function arguments in C?
  • (A) Arguments are optional
  • (B) Functions must always have arguments
  • (C) Function arguments must be integers
  • (D) A function cannot return values if it has arguments
Correct Answer: (A) Arguments are optional
24. How are formal parameters handled in a C function?
  • (A) They are created upon function entry and destroyed upon exit
  • (B) They are global variables
  • (C) They persist even after the function ends
  • (D) They are not necessary for any function
Correct Answer: (A) They are created upon function entry and destroyed upon exit
25. What is the correct syntax for calling a function with an argument in C?
  • (A) function();
  • (B) function(x);
  • (C) function(int);
  • (D) void function();
Correct Answer: (B) function(x);
26. Which of the following is a valid declaration for a function without arguments and without return value?
  • (A) void function();
  • (B) int function();
  • (C) float function();
  • (D) char function();
Correct Answer: (A) void function();
27. Which method passes a copy of an argument’s value to a function?
  • (A) Call by value
  • (B) Call by reference
  • (C) Pass by address
  • (D) Direct pass
Correct Answer: (A) Call by value
28. Which method passes the address of the argument to a function?
  • (A) Call by value
  • (B) Call by reference
  • (C) Call by address
  • (D) Pass by pointer
Correct Answer: (B) Call by reference
29. What happens to the actual parameter when using Call by Value?
  • (A) It gets modified
  • (B) It does not get modified
  • (C) The actual parameter is deleted
  • (D) The function accesses the actual parameter directly
Correct Answer: (B) It does not get modified
30. Which of the following languages does not support Call by Reference by default?
  • (A) C
  • (B) C++
  • (C) PHP
  • (D) Java
Correct Answer: (D) Java
31. Which statement is true for Call by Reference in C?
  • (A) The actual value is passed to the function
  • (B) The address of the actual argument is passed
  • (C) No values are passed
  • (D) The return type must be void
Correct Answer: (B) The address of the actual argument is passed
32. In which memory area are the local variables, including function arguments, stored in C?
  • (A) Stack
  • (B) Heap
  • (C) Global memory
  • (D) Data segment
Correct Answer: (A) Stack
33. What is the output of this code snippet?
                void func(int *x) {
                    *x = *x + 10;
                }
                int main() {
                    int y = 5;
                    func(&y);
                    printf("%d", y);
                    return 0;
                }
                
  • (A) 5
  • (B) 10
  • (C) 15
  • (D) Error
Correct Answer: (C) 15
34. What will happen when you pass an array to a function in C?
  • (A) The entire array is passed by value
  • (B) Only the base address of the array is passed
  • (C) The first element of the array is passed
  • (D) An error occurs
Correct Answer: (B) Only the base address of the array is passed
35. Which of the following methods is used to modify a variable inside a function?
  • (A) Pass by pointer
  • (B) Pass by value
  • (C) Call by constant
  • (D) Call by scope
Correct Answer: (A) Pass by pointer
36. What is required to implement Call by Reference in C?
  • (A) Pointers
  • (B) Arrays
  • (C) Macros
  • (D) Strings
Correct Answer: (A) Pointers
37. Which of the following functions returns the maximum of two numbers?
  • (A) max(a, b);
  • (B) a + b;
  • (C) int max(int a, int b);
  • (D) int max(a, b);
Correct Answer: (C) int max(int a, int b);
38. What will be the output of the following code?
                void swap(int a, int b) {
                    int temp = a;
                    a = b;
                    b = temp;
                }
                int main() {
                    int x = 5, y = 10;
                    swap(x, y);
                    printf("%d %d", x, y);
                    return 0;
                }
                
  • (A) 10 5
  • (B) 5 10
  • (C) Error
  • (D) Undefined behavior
Correct Answer: (B) 5 10
39. What is the primary difference between Call by Value and Call by Reference?
  • (A) Call by Value passes a copy, while Call by Reference passes the address
  • (B) Call by Value passes the address, while Call by Reference passes a copy
  • (C) Call by Reference requires recursion
  • (D) Both are the same
Correct Answer: (A) Call by Value passes a copy, while Call by Reference passes the address
40. What does the return statement do in a function?
  • (A) Ends the function and returns a value to the caller
  • (B) Ends the program
  • (C) Skips a loop
  • (D) Continues the function without returning a value
Correct Answer: (A) Ends the function and returns a value to the caller

4.2.3 - types of Functions.


41. What are the two types of functions in C?
  • (A) System functions and Library functions
  • (B) Library functions and User-defined functions
  • (C) Predefined functions and System functions
  • (D) Static functions and Dynamic functions
Correct Answer: (B) Library functions and User-defined functions
42. What is another name for a library function in C?
  • (A) Built-in function
  • (B) Predefined function
  • (C) Compiler function
  • (D) Standard function
Correct Answer: (A) Built-in function
43. Which of the following is a library function?
  • (A) int max(int, int);
  • (B) pow();
  • (C) userFunction();
  • (D) customFunction();
Correct Answer: (B) pow();
44. What is the main advantage of using library functions in C?
  • (A) They are automatically included in the code
  • (B) They do not need to be declared and defined by the programmer
  • (C) They always execute faster than user-defined functions
  • (D) They are more secure than user-defined functions
Correct Answer: (B) They do not need to be declared and defined by the programmer
45. Which of the following is an example of a user-defined function?
  • (A) sqrt()
  • (B) printf()
  • (C) myFunction()
  • (D) strcmp()
Correct Answer: (C) myFunction()
46. What header file is required for the sqrt() function?
  • (A) stdio.h
  • (B) math.h
  • (C) string.h
  • (D) conio.h
Correct Answer: (B) math.h
47. Which of the following is true for user-defined functions?
  • (A) They are always faster than library functions
  • (B) They must be declared and defined by the programmer
  • (C) They are stored in a separate file
  • (D) They are part of the compiler package
Correct Answer: (B) They must be declared and defined by the programmer
48. Which function calculates the power of a number in C?
  • (A) pow()
  • (B) power()
  • (C) exp()
  • (D) sqrt()
Correct Answer: (A) pow()
49. In which of the following situations would you use a user-defined function?
  • (A) When performing complex mathematical operations
  • (B) When a specific task needs to be repeated multiple times
  • (C) When no library function exists for the task
  • (D) Both B and C
Correct Answer: (D) Both B and C
50. What is the main disadvantage of user-defined functions compared to library functions?
  • (A) They cannot handle complex tasks
  • (B) They are less efficient than library functions
  • (C) They must be manually declared and defined by the programmer
  • (D) They cannot return a value
Correct Answer: (C) They must be manually declared and defined by the programmer
51. What is the purpose of the #include statement in C?
  • (A) To define user-defined functions
  • (B) To include library functions related to mathematical operations
  • (C) To enable system functions
  • (D) To optimize program performance
Correct Answer: (B) To include library functions related to mathematical operations
52. Which of the following is true about the function pow() in C?
  • (A) It is a user-defined function
  • (B) It takes two arguments and returns the result of the first raised to the power of the second
  • (C) It calculates the square root of a number
  • (D) It is defined in stdio.h
Correct Answer: (B) It takes two arguments and returns the result of the first raised to the power of the second
53. Which of the following statements is correct for user-defined functions?
  • (A) They do not require a return type
  • (B) They can only return integer values
  • (C) They can return any data type
  • (D) They are always void functions
Correct Answer: (C) They can return any data type
54. Which of the following is NOT a C library function?
  • (A) printf()
  • (B) strcpy()
  • (C) calculateArea()
  • (D) strlen()
Correct Answer: (C) calculateArea()
55. Which function is used to find the square root of a number in C?
  • (A) pow()
  • (B) sqrt()
  • (C) abs()
  • (D) log()
Correct Answer: (B) sqrt()
56. Which of the following is a major benefit of user-defined functions?
  • (A) They reduce the overall complexity of a program by allowing code reuse
  • (B) They automatically optimize program performance
  • (C) They do not require header files
  • (D) They are faster than library functions
Correct Answer: (A) They reduce the overall complexity of a program by allowing code reuse
57. What is the output of the following program?
                #include 
                int add(int a, int b) {
                    return a + b;
                }
                int main() {
                    int result = add(3, 4);
                    printf("%d", result);
                    return 0;
                }
                
  • (A) 7
  • (B) 3
  • (C) 4
  • (D) Error
Correct Answer: (A) 7
58. What must be true for a function to be considered user-defined?
  • (A) It must be written by the programmer
  • (B) It must include only one argument
  • (C) It must not use any library functions
  • (D) It must return an integer
Correct Answer: (A) It must be written by the programmer
59. In which scenario would you most likely use a user-defined function instead of a library function?
  • (A) When performing a common mathematical operation
  • (B) When implementing custom logic specific to the program
  • (C) When calling a function from an external library
  • (D) When requiring high-performance code
Correct Answer: (B) When implementing custom logic specific to the program
60. Which statement about C library functions is false?
  • (A) They are predefined and part of the C standard library
  • (B) They must be declared by the user before use
  • (C) They save development time
  • (D) They are optimized for performance
Correct Answer: (B) They must be declared by the user before use

4.2.4 - Predefined vs User Defined functions.


61. Which of the following is true about predefined functions?
  • (A) They need to be defined by the programmer
  • (B) They are also known as library functions
  • (C) They cannot be used in C programs
  • (D) They must always return an integer value
Correct Answer: (B) They are also known as library functions
62. Which of the following is NOT a predefined function in C?
  • (A) printf()
  • (B) scanf()
  • (C) main()
  • (D) getch()
Correct Answer: (C) main()
63. Which of the following is NOT a part of a user-defined function in C?
  • (A) Function declaration
  • (B) Function call
  • (C) Function name
  • (D) Header file
Correct Answer: (D) Header file
64. What is the role of the return type in a function definition?
  • (A) It specifies the name of the function
  • (B) It specifies the data type of the value the function returns
  • (C) It specifies the parameters the function takes
  • (D) It specifies how many times the function will execute
Correct Answer: (B) It specifies the data type of the value the function returns
65. Which keyword is used as a return type if a function does not return any value?
  • (A) int
  • (B) void
  • (C) char
  • (D) return
Correct Answer: (B) void
66. What is a "parameter" in a function?
  • (A) A value that is always returned by the function
  • (B) A placeholder that receives values when the function is called
  • (C) The return value of the function
  • (D) A built-in function
Correct Answer: (B) A placeholder that receives values when the function is called
67. What is the main advantage of using user-defined functions?
  • (A) They are automatically included in the C library
  • (B) They make the code more readable and reusable
  • (C) They are always faster than predefined functions
  • (D) They do not need a function declaration
Correct Answer: (B) They make the code more readable and reusable
68. In a user-defined function, what does the function body contain?
  • (A) The name of the function
  • (B) The data type of the return value
  • (C) The statements that describe what the function does
  • (D) The parameters of the function
Correct Answer: (C) The statements that describe what the function does
69. What is the correct order for defining a user-defined function in C?
  • (A) Function call, function declaration, function definition
  • (B) Function definition, function declaration, function call
  • (C) Function declaration, function call, function definition
  • (D) Function declaration, function definition, function call
Correct Answer: (D) Function declaration, function definition, function call
70. Which of the following is an advantage of using functions in C?
  • (A) They increase code complexity
  • (B) They improve code reusability and readability
  • (C) They make the code harder to debug
  • (D) They cannot return values
Correct Answer: (B) They improve code reusability and readability
71. In the function declaration int add(int, int);, what does int before add signify?
  • (A) The name of the function
  • (B) The return type of the function
  • (C) The parameter types
  • (D) The number of parameters
Correct Answer: (B) The return type of the function
72. What is the purpose of function declaration in C?
  • (A) To define the function body
  • (B) To specify the return type and parameters of the function to the compiler
  • (C) To execute the function
  • (D) To repeat code inside the function
Correct Answer: (B) To specify the return type and parameters of the function to the compiler
73. Which of the following can be considered as an example of a user-defined function?
  • (A) printf()
  • (B) scanf()
  • (C) myFunction()
  • (D) main()
Correct Answer: (C) myFunction()
74. What must be included in the function definition?
  • (A) The header file
  • (B) The function body
  • (C) The return value
  • (D) The parameters only
Correct Answer: (B) The function body
75. Which of the following is NOT a characteristic of predefined functions?
  • (A) They are part of the C standard library
  • (B) They need to be manually defined by the programmer
  • (C) They save time in development
  • (D) They are optimized for performance
Correct Answer: (B) They need to be manually defined by the programmer
76. What is the correct syntax for calling a user-defined function named calculate with two integer parameters a and b?
  • (A) calculate;
  • (B) calculate(a b);
  • (C) calculate(a, b);
  • (D) calculate(a) b;
Correct Answer: (C) calculate(a, b);
77. Which statement about function parameters is true?
  • (A) A function must always have at least one parameter
  • (B) The parameters are part of the function name
  • (C) Parameters are optional; a function can have zero parameters
  • (D) Parameters cannot have data types
Correct Answer: (C) Parameters are optional; a function can have zero parameters
78. Which of the following is an advantage of using functions in a program?
  • (A) Functions increase memory usage
  • (B) Functions reduce the need for repeated code
  • (C) Functions make debugging harder
  • (D) Functions are always slower than using raw code
Correct Answer: (B) Functions reduce the need for repeated code
79. Which of the following describes a function call in C?
  • (A) It defines the function
  • (B) It declares the function
  • (C) It executes the function
  • (D) It specifies the return type of the function
Correct Answer: (C) It executes the function
80. What is the output of the following program?
                #include <stdio.h>
                void greet() {
                    printf("Hello, World!");
                }
                int main() {
                    greet();
                    return 0;
                }
                
  • (A) Error
  • (B) No output
  • (C) Hello, World!
  • (D) Undefined
Correct Answer: (C) Hello, World!

4.2.5 - User Defined functions.


81. Which of the following is true about user-defined functions?
  • (A) They are predefined and cannot be modified
  • (B) They are modifiable to suit the programmer's needs
  • (C) They cannot be reused in other programs
  • (D) They are always faster than library functions
Correct Answer: (B) They are modifiable to suit the programmer's needs
82. What is the benefit of user-defined functions?
  • (A) They are predefined in the C library
  • (B) They do not require a return type
  • (C) They make code easier to understand and maintain
  • (D) They must use global variables
Correct Answer: (C) They make code easier to understand and maintain
83. Which statement is true about user-defined functions?
  • (A) User-defined functions cannot take parameters
  • (B) User-defined functions must always return an integer
  • (C) User-defined functions can be reused in different programs
  • (D) User-defined functions must be declared in the C library
Correct Answer: (C) User-defined functions can be reused in different programs
84. What is the output of the following program?
                #include <stdio.h>
                int sum(int a, int b) {
                    return a + b;
                }
                int main() {
                    int a = 10, b = 20;
                    int result = sum(a, b);
                    printf("Sum is: %d", result);
                    return 0;
                }
                
  • (A) Error
  • (B) No output
  • (C) Sum is: 30
  • (D) Undefined
Correct Answer: (C) Sum is: 30
85. What is the function signature of the following user-defined function?
                int multiply(int a, int b) {
                    return a * b;
                }
                
  • (A) multiply()
  • (B) int multiply(int, int)
  • (C) multiply(int, int)
  • (D) int multiply()
Correct Answer: (B) int multiply(int, int)
86. In a user-defined function, what does the keyword return do?
  • (A) It ends the program
  • (B) It ends the function and sends a value back to the calling function
  • (C) It declares the return type of the function
  • (D) It declares the parameters of the function
Correct Answer: (B) It ends the function and sends a value back to the calling function
87. Which part of the user-defined function contains the actual code?
  • (A) Function declaration
  • (B) Function prototype
  • (C) Function body
  • (D) Function header
Correct Answer: (C) Function body
88. In the given code, what is int sum(int a, int b) called?
                int sum(int a, int b) {
                    return a + b;
                }
                
  • (A) Function body
  • (B) Function definition
  • (C) Function call
  • (D) Function declaration
Correct Answer: (B) Function definition
89. Which of the following is an advantage of user-defined functions?
  • (A) They are predefined in the C library
  • (B) They cannot take arguments
  • (C) They can reduce code repetition
  • (D) They do not need a return type
Correct Answer: (C) They can reduce code repetition
90. Which of the following correctly calls a function named add with arguments 5 and 10?
  • (A) add(5 10);
  • (B) add(5, 10);
  • (C) add();
  • (D) add(5,10)
Correct Answer: (B) add(5, 10);
91. What is the output of the following code?
                #include <stdio.h>
                int multiply(int a, int b) {
                    return a * b;
                }
                int main() {
                    int x = 5, y = 6;
                    int result = multiply(x, y);
                    printf("Product is: %d", result);
                    return 0;
                }
                
  • (A) Product is: 11
  • (B) Product is: 30
  • (C) Product is: 56
  • (D) Product is: 25
Correct Answer: (B) Product is: 30
92. Which of the following is necessary when defining a user-defined function?
  • (A) Declaring the function inside main()
  • (B) Defining the function before using it
  • (C) Returning a value of type void
  • (D) Using global variables
Correct Answer: (B) Defining the function before using it

4.2.6 - Recursion.


93. What is a user-defined function in C?
  • (A) A function provided by the C library
  • (B) A function created by the programmer
  • (C) A function with no parameters
  • (D) A function that automatically executes
Correct Answer: (B) A function created by the programmer
94. Which of the following is a valid syntax for a function declaration in C?
  • (A) int function()
  • (B) int function
  • (C) function int()
  • (D) void return()
Correct Answer: (A) int function()
95. What does the keyword 'void' indicate in a function declaration?
  • (A) The function does not return any value
  • (B) The function returns an integer
  • (C) The function has no parameters
  • (D) The function has no body
Correct Answer: (A) The function does not return any value
96. What is the default return type of a function in C?
  • (A) int
  • (B) float
  • (C) char
  • (D) void
Correct Answer: (A) int
97. What is recursion?
  • (A) A function calling itself
  • (B) A function calling other functions
  • (C) A function that does not return a value
  • (D) A function without any parameters
Correct Answer: (A) A function calling itself
98. Which of the following problems is best solved using recursion?
  • (A) Loop-based counting
  • (B) Sorting large datasets
  • (C) Calculating factorial
  • (D) Printing a string
Correct Answer: (C) Calculating factorial
99. Which of the following is an example of a library function in C?
  • (A) printf()
  • (B) userFunction()
  • (C) main()
  • (D) func()
Correct Answer: (A) printf()
100. What is the output of the following code?
                int main() {
                    int x = 5;
                    printf("%d", fact(x));
                    return 0;
                }
                int fact(int n) {
                    if (n == 0)
                        return 1;
                    else
                        return n * fact(n - 1);
                }
                
  • (A) 120
  • (B) 24
  • (C) 5
  • (D) 0
Correct Answer: (A) 120
101. What is the key difference between call by value and call by reference?
  • (A) Call by value passes a copy; call by reference passes the address
  • (B) Call by reference passes a copy; call by value passes the address
  • (C) Call by value and call by reference are the same
  • (D) Call by value changes the original variable
Correct Answer: (A) Call by value passes a copy; call by reference passes the address
102. Which of the following function types does not return any value?
  • (A) int
  • (B) void
  • (C) float
  • (D) double
Correct Answer: (B) void
103. Which of the following is necessary for recursion to work properly?
  • (A) Infinite calls
  • (B) Base case
  • (C) For loop
  • (D) Exit condition
Correct Answer: (B) Base case
104. Which of the following is true about recursion?
  • (A) It requires more memory than an iterative solution
  • (B) It always executes faster than loops
  • (C) Recursion and loops perform equally
  • (D) Recursion is always better than iteration
Correct Answer: (A) It requires more memory than an iterative solution
105. In C, which header file is required to use the library function pow()?
  • (A) stdio.h
  • (B) math.h
  • (C) string.h
  • (D) stdlib.h
Correct Answer: (B) math.h
106. What is a function prototype in C?
  • (A) A blueprint of a function
  • (B) A recursive function
  • (C) A user-defined function
  • (D) An undefined function
Correct Answer: (A) A blueprint of a function
107. What is the termination condition in recursion called?
  • (A) Recursive case
  • (B) Base case
  • (C) Stop point
  • (D) Function body
Correct Answer: (B) Base case
108. Which function call method allows the actual value to remain unchanged in the calling function?
  • (A) Call by value
  • (B) Call by reference
  • (C) Call by pointer
  • (D) Call by argument
Correct Answer: (A) Call by value
109. Which of the following library functions is used to find the length of a string?
  • (A) strlen()
  • (B) strcpy()
  • (C) strcmp()
  • (D) strcat()
Correct Answer: (A) strlen()
110. What happens if a recursive function lacks a base case?
  • (A) Infinite recursion
  • (B) It terminates immediately
  • (C) It throws a compile-time error
  • (D) It returns a null value
Correct Answer: (A) Infinite recursion
111. Which type of variable stores the return address of the function call in recursion?
  • (A) Stack
  • (B) Heap
  • (C) Queue
  • (D) Linked List
Correct Answer: (A) Stack
112. What is the primary advantage of recursion over iteration?
  • (A) Simplicity and clarity in solving complex problems
  • (B) Faster execution time
  • (C) Uses less memory
  • (D) Easier to debug
Correct Answer: (A) Simplicity and clarity in solving complex problems

4.2.7 - Function With Variable Number of Argument.


113. What is a function in C programming?
  • (A) A block of code performing a specific task
  • (B) A type of variable
  • (C) A file handler
  • (D) A preprocessor directive
Correct Answer: (A) A block of code performing a specific task
114. Which of the following is a built-in function in C?
  • (A) main()
  • (B) printf()
  • (C) sum()
  • (D) scanf()
Correct Answer: (B) printf()
115. Which header file is required for using printf() and scanf() functions?
  • (A) stdlib.h
  • (B) stdio.h
  • (C) conio.h
  • (D) string.h
Correct Answer: (B) stdio.h
116. Which function call method allows the actual value to remain unchanged in the calling function?
  • (A) Call by value
  • (B) Call by reference
  • (C) Call by pointer
  • (D) Call by argument
Correct Answer: (A) Call by value
117. Which function in C is used to allocate memory dynamically?
  • (A) malloc()
  • (B) printf()
  • (C) calloc()
  • (D) free()
Correct Answer: (A) malloc()
118. In C, which keyword is used to declare a function returning no value?
  • (A) void
  • (B) int
  • (C) return
  • (D) char
Correct Answer: (A) void
119. What is the default return type of a function in C if no return type is explicitly declared?
  • (A) int
  • (B) void
  • (C) float
  • (D) char
Correct Answer: (A) int
120. How many times can the main() function be called in a C program?
  • (A) Only once
  • (B) Twice
  • (C) Multiple times
  • (D) Depends on the compiler
Correct Answer: (A) Only once
121. Which function is used to compare two strings in C?
  • (A) strcmp()
  • (B) strcat()
  • (C) strcpy()
  • (D) strrev()
Correct Answer: (A) strcmp()
122. Which of the following is the correct syntax to declare a function in C?
  • (A) return_type function_name(parameter list);
  • (B) function_name(parameter list): return_type;
  • (C) return_type (parameter list) function_name;
  • (D) parameter list return_type function_name;
Correct Answer: (A) return_type function_name(parameter list);
123. Which of these is a valid function declaration in C?
  • (A) int sum();
  • (B) void sum;
  • (C) return sum();
  • (D) int sum(int);
Correct Answer: (D) int sum(int)
124. Which function would you use to find the length of a string in C?
  • (A) strlen()
  • (B) strcat()
  • (C) strcpy()
  • (D) strcmp()
Correct Answer: (A) strlen()
125. What is recursion in C?
  • (A) A function calling itself
  • (B) A function calling another function
  • (C) A function without parameters
  • (D) A function that returns a pointer
Correct Answer: (A) A function calling itself
126. Which of the following functions can change the value of the actual parameters passed to it?
  • (A) Call by value
  • (B) Call by reference
  • (C) Call by array
  • (D) Call by variable
Correct Answer: (B) Call by reference
127. Which function is used to open a file in C?
  • (A) fopen()
  • (B) close()
  • (C) read()
  • (D) fwrite()
Correct Answer: (A) fopen()
128. What is the return type of the malloc() function in C?
  • (A) void*
  • (B) int
  • (C) char
  • (D) float
Correct Answer: (A) void*
129. Which C function is used to get the length of an array?
  • (A) sizeof()
  • (B) length()
  • (C) array_length()
  • (D) strlen()
Correct Answer: (A) sizeof()
130. Which function is used to release the memory allocated dynamically in C?
  • (A) free()
  • (B) delete()
  • (C) malloc()
  • (D) deallocate()
Correct Answer: (A) free()
131. Which of the following is a function that does not return any value?
  • (A) void function()
  • (B) int function()
  • (C) char function()
  • (D) float function()
Correct Answer: (A) void function()
132. What does the return keyword do in a function?
  • (A) It exits the function and returns a value
  • (B) It prints a value
  • (C) It allocates memory
  • (D) It defines the function's name
Correct Answer: (A) It exits the function and returns a value