29.10.25

20. Reverse String Using Recursion The One Where Aarav Thinks He’s a DJ

    

hello everyone 

So today's DSU coding session started peacefully until sir said: “Write a program to reverse a string using recursion.” And before anyone could even open their compiler, Aarav jumped up like he’s performing at Sunburn: “DUDE, I REVERSE TRACKS DAILY. STRING REVERSE IS NOTHING.” Yes he really compared recursion to DJ-ing. Rahul’s soul left his body for 2 seconds.

What’s Actually Happening?

Rahul, our unofficial group teacher, explained:

  1. Recursion keeps moving forward in the string
  2. It stops when it hits '\0'
  3. Then the real magic begins
  4. As the function returns step-by-step (unwinding),
  5. it prints each character backward
  6. No loops
  7. No extra arrays
  8. Pure logical elegance (unlike our group discussions)

Aarav said it as:
“Means go ahead, but print while coming back?”
He actually understood it. Miracles do happen.

How We Divided the Work

  • Rahul handled the recursion logic
    (and reminded Aarav 5 times that DJ skills don’t count as coding skills)

  • Aarav kept giving commentary like:
    “Reverse it like a drop! Backward drop incoming!”

  • I (Daksh) just printed the reversed string
    and maintained peace as usual.

Why This Program Is Cool

Works without loops, Uses the call stack to reverse automatically, Simple, elegant, and extremely clean, Makes you look smarter than you feel

In simple words recursion does all the heavy lifting while we pretend to work.

Code:

 #define _CRT_SECURE_NO_WARNINGS
 #include <stdio.h>
 
 void printReverseString(char givenString[]) {
     if (*givenString == '\0')
         return;
     printReverseString(givenString + 1);
     printf("%c", *givenString);
 }
 
 int main() {
     char givenString[100];
     printf("Enter a string: ");
     scanf("%s", givenString);
     printf("Reversed string: ");
     printReverseString(givenString);
     printf("\n");
     return 0;
 }

Output:


← Previous 🏠 Homepage Next Chapter →

No comments:

Post a Comment

rating System

Loading...

A Friendship Story of Learning Data Structures with C

Sr. No. DSU BLOGS CHAPTERS 1 Array Operations in C, The Group of Friendship (Create, Insert, Delete ...