C - Control Statements Practice Test.3

  1. What is a nested function in C?

    A) A function that calls itself

    B) A function declared inside another function

    C) A function with multiple parameters

    D) A function that returns a nested data structure

  2. What is the scope of a nested function?

    A) It can only be accessed within the function it is declared in

    B) It can be accessed globally

    C) It can be accessed by other functions within the same file

    D) It can be accessed by any function in the program

  3. What is the primary benefit of using nested functions in programming?

    A) They reduce code complexity

    B) They allow for faster execution of code

    C) They enable multi-threading

    D) They eliminate the need for global variables

  4. Can a nested function access the variables of the outer function?

    A) Yes, it can access all variables of the outer function

    B) No, it can't access any variables of the outer function

    C) It can only access global variables

    D) It can access variables declared as static in the outer function

  5. What is the term for a nested function that is defined and called within the same function?

    A) Nested function

    B) Recursive function

    C) Lambda function

    D) Inner function

  6. Which keyword is used to define a nested function in C?

    A) nested

    B) inner

    C) static

    D) local

  7. What is the advantage of using nested functions in C?

    A) Improved code reusability

    B) Reduced memory consumption

    C) Enhanced code organization

    D) Simplified debugging

  8. In C, which type of function can be called recursively?

    A) Only nested functions

    B) Only global functions

    C) Only static functions

    D) Any function

  9. What is recursion in the context of nested functions?

    A) It is a type of loop construct

    B) It is a type of function call within the same function

    C) It is a type of data structure

    D) It is a type of nested variable

  10. What is the potential risk of using recursion in nested functions?

    A) Stack overflow error

    B) Memory leak

    C) Compilation error

    D) Loss of code clarity

  11. What is the significance of the return statement in the main() function?

    A) Call by Reference

    B) Call by Value

    C) Call by Pointer

    D) Call by Name

  12. Which parameter passing mechanism creates a copy of the actual parameter in the function?

    A) Call by Reference

    B) Call by Value

    C) Call by Pointer

    D) Call by Name

  13. What happens when you pass an array as a parameter to a function in C?

    A) The entire array is passed by value

    B) A reference to the array is passed

    C) The first element of the array is passed

    D) It is not possible to pass an array to a function

  14. Which parameter passing mechanism allows the function to modify the original value of the argument?

    A) Call by Reference

    B) Call by Value

    C) Call by Pointer

    D) Call by Name

  15. What is the default parameter passing mechanism in C?

    A) Call by Reference

    B) Call by Value

    C) Call by Pointer

    D) Call by Name

  16. Which of the following is true for call by reference?

    A) It is more memory-efficient than call by value

    B) Changes made to the parameter inside the function do not affect the original value

    C) It is the default parameter passing mechanism in C

    D) It is also known as pass by address

  17. What is the main advantage of call by value?

    A) It allows the function to modify the original value of the argument

    B) It is more memory-efficient than call by reference

    C) Changes made to the parameter inside the function do not affect the original value

    D) It is the default parameter passing mechanism in C

  18. What happens when you pass a constant variable to a function in C?

    A) The function cannot access the variable

    B) The function can modify the value of the variable

    C) The function receives a copy of the variable

    D) The variable becomes global

  19. Which parameter passing mechanism is used when you pass a pointer to a function?

    A) Call by Reference

    B) Call by Value

    C) Call by Pointer

    D) Call by Name

  20. What is the main advantage of call by pointer?

    A) It is more memory-efficient than call by value

    B) It allows the function to modify the original value of the argument

    C) Changes made to the parameter inside the function do not affect the original value

    D) It is the default parameter passing mechanism in C

  21. What does a "Stack Overflow Error" indicate in recursion?

    A) The program has too many loops.

    B) The stack memory is exhausted due to excessive function calls.

    C) The recursion depth is too shallow.

    D) The program has a syntax error.

  22. How can you prevent a stack overflow error in recursive functions?

    A) Increase the stack size.

    B) Reduce the number of recursive calls.

    C) Use more global variables.

    D) Remove the base case.

  23. What is the purpose of a base case in recursive functions?

    A) To make the program run faster.

    B) To provide a way to exit the recursion.

    C) To increase the stack size.

    D) To add more function calls.

  24. What happens if a recursive function does not have a base case?

    A) It will run faster.

    B) It will result in a stack overflow error.

    C) It will exit the program gracefully.

    D) It will print an error message.

  25. What is the purpose of recursion in programming?

    A) To make programs shorter.

    B) To make programs more complicated.

    C) To solve problems by breaking them down into smaller, identical subproblems.

    D) To eliminate the need for loops.