-
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
Answer: B) A function declared inside another function
-
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
Answer: A) It can only be accessed within the function it is declared in
-
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
Answer: A) They reduce code complexity
-
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
Answer: D) It can access variables declared as static in the outer function
-
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
Answer: D) Inner function
-
Which keyword is used to define a nested function in C?
A) nested
B) inner
C) static
D) local
Answer: C) static
-
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
Answer: C) Enhanced code organization
-
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
Answer: D) Any function
-
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
Answer: B) It is a type of function call within the same function
-
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
Answer: A) Stack overflow error
-
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
Answer: B) Call by Value
-
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
Answer: B) Call by Value
-
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
Answer: B) A reference to the array is passed
-
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
Answer: A) Call by Reference
-
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
Answer: B) Call by Value
-
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
Answer: D) It is also known as pass by address
-
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
Answer: C) Changes made to the parameter inside the function do not affect the original value
-
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
Answer: C) The function receives a copy of the variable
-
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
Answer: C) Call by Pointer
-
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
Answer: B) It allows the function to modify the original value of the argument
-
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.
Answer: B) The stack memory is exhausted due to excessive function calls.
-
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.
Answer: B) Reduce the number of recursive calls.
-
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.
Answer: B) To provide a way to exit the recursion.
-
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.
Answer: B) It will result in a stack overflow error.
-
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.
Answer: C) To solve problems by breaking them down into smaller, identical subproblems.