Question
Consider the following C code snippet: Â Â
#include   int factorial(int n) {     if (n == 0) {       return 1;     }     // Potential error here     return n * factorial(n);   }   int main() {     printf("%d\n", factorial(3));     return 0;   }   What will be the output or behavior of the program when factorial(3) is called?Solution
The error lies in the recursive call: return n * factorial(n);. Instead of calling factorial(n - 1) to move towards the base case, the function calls itself with the same argument n. This creates an infinite recursion loop. When factorial(3) is called, it calls factorial(3) again, which calls factorial(3) indefinitely. Each call consumes stack memory, eventually leading to a stack overflow and typically a segmentation fault. The correct recursive call should be return n * factorial(n - 1);.
Since which year has the Reserve Bank of India (RBI) been observing Financial Literacy Week (FLW)?
Balance of trade is the _______________.
Which of the following is not part of the World Bank Group of Institutions?
What does 'SLR' stand for in the context of banking regulations?
Which of the following is true regarding GDP?
i. In calculating GDP only final marketable goods and services are considered
ii. GDP c...
_____________ launched the e-Sawaari India Electric Bus Coalition, in partnership with Convergence Energy Service Limited (CESL) and World Resources Ins...
Which bank has been awarded the global 'Celent Model Bank' award under the category – 'Payments System Transformation'?
Philips Curve is a graphic curve advocating a relationship between which factors?
The annual rate of growth of GDP has been the lowest in which Five Year Plan?
A set of three statements regarding measures of National income are given below.
Read each statement and answer whether each statement is true or...