Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8052809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:39:10+00:00 2026-06-05T07:39:10+00:00

#include <stdio.h> #include <stdlib.h> void reprint(char *a[]) { if(*a) { printf(%d ,a); reprint(a+1); printf(%s

  • 0
#include <stdio.h>
#include <stdlib.h>

void reprint(char *a[]) {
    if(*a) {
            printf("%d ",a);
            reprint(a+1);
            printf("%s ",*a);
    }
}

int main() {
    char *coll[] = {"C", "Objective", "like", "don't", "I", NULL};
    reprint(coll);
    printf("\n");
    return EXIT_SUCCESS;
}

As the more experienced will know, this prints the array in reverse. I don’t quite understand how!

I need help understanding what reprint(char *a[]) does. I understand pointer arithmetic to a degree, but from inserting printfs here and there, I’ve determined that the function increments up to the array end, and then back down to the start, only printing on the way down. However, I do not understand how it does this; all I’ve managed to understand by looking at the actual code is that if *a isn’t NULL, then call reprint again, at the next index.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:39:12+00:00Added an answer on June 5, 2026 at 7:39 am

    The key to understanding this type of recursion is to know how stacks work.

    First: each time reprint() calls itself with (a+1), then a+1 is pushed onto the stack. This means the called reprint() gets a copy of the char** as an argument. The calling reprint’s ‘a’ is not touched. Like you said, this goes on until the passed char ** is NULL, i.e. the last element in the array. Then the test ‘if (*a)’ becomes false and reprint will not be called any deeper.

    Note at this point, all 5 calls to reprint are ‘waiting’ for it to return, so none of the printf’s after the recursive call to reprint haven’t been called yet. Also note that all 5 calls have their own ‘a’ pointer. This is essential.

    Now, since the last call of reprint doesn’t call reprint anymore, it will just return. The second to last reprint, the one which has an ‘a’ pointing to the string “I”, can then continue with the next statement after the call to reprint, which is the printf of “I”. Once this is done, this function also returns. The third to last reprint, the one with ‘a’ pointing to the string “don’t” can then also continue and prints “don’t”, etc…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#include <stdio.h> #include <stdlib.h> int main() { void *malloc(size_t size); char *ptr, *retval; ptr
#include <string.h> #include <stdlib.h> #include <stdio.h> int main(void) { unsigned char *stole; unsigned char
#include <stdio.h> #include <stdlib.h> int main(int argc,char *argv[]) { system(PAUSE); return 0; } After
#include<stdio.h> #include<sys/types.h> #include<stdlib.h> int turn; int flag[2]; int main(void) { int pid,parent=1; printf(before vfork\n);
#include <stdio.h> #include <stdlib.h> #include <string.h> void main() { typedef int (FuncPtr)(); char asmFunc[]
#include <stdio.h> #include <stdlib.h> void copyint(char *i,char** temp); int main() { char* a=00313; char*
The program is: #include <stdio.h> #include <stdlib.h> int main(void) { char *a=abc,*ptr; ptr=a; ptr++;
#include <stdio.h> #include <stdlib.h> int main( void ) { char *ptr1 = Hello World\n;
I am thinking of something like: #include <stdio.h> #include <conio.h> #include <stdlib.h> int main(void)
#include <stdio.h> #include <stdlib.h> int main (void) { double f; printf (What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.