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);.
SA 500 deals with which of the following?
FEMA, 1999, replaced which of the following previous legislations?
Who has propounded the Theory Z?
U/s 208, it is obligatory for an assessee to pay advance tax where the tax payable is
A limitation of a Data Flow Diagram (DFD) is that it:Â
Under purchase method of consolidation (older term), goodwill on consolidation arises when:
What is the maximum limit for insurance coverage provided by the Deposit Insurance and Credit Guarantee Corporation (DICGC) in India?
Stock on 1st Jan = ₹1,00,000
Purchases = ₹2,50,000
Sales = ₹3,00,000
Gross Profit = 25% on sales
Stock destroyed in fi...
An increase in the credit period allowed to debtors will likely:
If the MOS = 40000 units and BE units are 35000 and PV ratio is 60%. Calculate profit if revenue per unit is 8.