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

  • Home
  • SEARCH
  • 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 6995041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:58:13+00:00 2026-05-27T19:58:13+00:00

I have been writing a program that is quite complex compared to what I

  • 0

I have been writing a program that is quite complex compared to what I have dealt with until now. Anyways at some point I am supposed to write a function that will manipulate a struct list. I’m trying to make this question as simple as possible so I wrote down a pretty simple piece of code just for reference.

Here is the thing: at first I call testf from another function providing it with a valid current as well as an i with a value of 0. This means that testf will call itself about 100 times before it starts accessing the rest of the code. This is when all the generated instances of testf will start getting resolved.

 void testf(listnode *current, int *i) {
   wordwagon *current2;

   current2 = current;
   if (*i < 100) {
     *i = *i + 1;
     current2 = current2->next;
     testf(current2, i);
   }


   current = current->next;
   return;
 }

If, let’s say, I have enough connected list nodes at my disposal, is current = current->next; the correct way for the “last” testf function to access and edit the caller’s current2 value (which is this function’s current), or am I horribly wrong?
If I am, what is the way to make changes to the caller function’s variables from inside the called function and be sure they won’t go away as soon as the called function returns? I find it kind of hard to get a good grasp on how pointers work.

It is very likely that I have left out important information or that I haven’t asked my question clearly enough. Please inform me if that is the case so I can edit in whatever you need.

Thanks in advance.

  • 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-05-27T19:58:14+00:00Added an answer on May 27, 2026 at 7:58 pm

    You can pass pointer to a pointer in your function, and derefrence it to get a listnode pointer back , here is how the code will look like after that ( not tested for compilation ) :

    void testf(listnode **current, int *i) {  // accept pointer to listnode pointer
       wordwagon *current2;
    
       current2 = *current;   // retreive pointer value by dereferece
       if (*i < 100) {
         *i = *i + 1;
         current2 = current2->next;
         testf(&current2, i);  // recursively call by reference to the pointer
       }
    
       *current = (*current)->next; /* change the current pointer next pointer, CORRECTED as suggested by Azure */
       return;
     }
    

    Here is a list of really good articles for learning pointers :

    a) http://cslibrary.stanford.edu/102/PointersAndMemory.pdf

    b) http://cslibrary.stanford.edu/103/LinkedListBasics.pdf

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

Sidebar

Related Questions

For about a year I have been thinking about writing a program that writes
I have been writing a program that watches a directory and when files are
I have tried writing program that plays a sound file but have been unsuccessful
I have been writing some code that detects add and removal of USB devices,
Recently I have been writing a program in C++ that pings three different websites
I have been writing C++ Console/CMD-line applications for about a year now and would
I have been writing DLL on C++, that will be use in C#. DLL
I have been writing web applications for quite sometime in PHP with MySQL. I
I have been writing articles on the wordpress.com blog , now I am looking
I have been experimenting with writing applications that use a local SQL Database to

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.