DEV Community

Divya Divya
Divya Divya

Posted on

Debugging?

Debugging is the systematic process of identifying, analyzing, and removing bugs or errors from software or hardware, typically occurring after testing.

Recursion
Recursion debugging involves checking the base condition, ensuring the recursive call updates the input, and tracing the function step-by-step to identify errors.

Example :

void print(int n) {
    if (n == 5) return;

    System.out.println(n);
    print(n); // mistake
}

Enter fullscreen mode Exit fullscreen mode

Execution Flow:

Step:1
Call → print(1)
n = 1
1 == 5 ❌
print → 1
next call → print(1)

Step:2
Call → print(1)
n = 1 (same)
1 == 5 ❌
print → 1
next call → print(1)

Step:3
Call → print(1)
n = 1
print → 1
next call → print(1)

  • print(n) → n does not change
  • Same value is repeat
  • infinite recursion / stack overflow

Top comments (0)