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 7195061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:30:11+00:00 2026-05-28T20:30:11+00:00

So here i am struggling with this program, i was trying to find out

  • 0

So here i am struggling with this program, i was trying to find out how can I use a
array of pointers declared into main, in a recursive function to memorize data, the question that
arises here is if it’s the same approach as for a single pointer, what about for a struct type ?
what is the best way to pass by reference a variable/array to a recursive function ?

#include <stdio.h>
#include <stdlib.h>
#define N 1

void f(int i,int j,int *cnt);

int j=0;

int main(int argc, char *argv[])
{
  int *cnt=0;
  f(0,++j,&cnt);
  printf("------ %d ---- \n",cnt);
  system("PAUSE");  
  return 0;
}

void f(int i,int j,int *cnt){

   if(i>N){
          printf("---if --- %d ---- %d \n",i,j);
          (*cnt)++;
          return;
          }

   (*cnt)++;
   printf("---bg --- %d ---- %d \n",i,j);
   f(i+1,++j,cnt);
   f(i+1,++j,cnt);        
}

Another thing i’d like to know is how does the recursive functions handle the ++i and i++ and i+1 increments (when passed as parameters),

  • 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-28T20:30:11+00:00Added an answer on May 28, 2026 at 8:30 pm
    int main(int argc, char *argv[])
    {
        int *cnt=0;
        f(0,++j,&cnt);
        printf("------ %d ---- \n",(*cnt));
        system("PAUSE");  
        return 0;
    }
    

    needs to be

    int main(int argc, char *argv[])
    {
        int intStorage = 0;//<---- As Oli said.
        int *cnt= &intStorage;
        f(0,++j,cnt);//<-------AMPERSAND removed, overly dereferenced.
        printf("------ %d ---- \n",(*cnt));
        system("PAUSE");  
        return 0;
    }
    

    ++i and i++ and i+1 (when passed as parameters):

    1. ++i: i + 1 is passed and is also the value i takes afterwards.
    2. i++: i is passed and i = i + 1 after the call.
    3. i+1: i + 1 is passed but i remains as just i afterwards.

    I’ll try and fix your function a little too:

    void f(int i,int j,int *cnt){
    
        if(i>N){
            printf("---if --- %d ---- %d \n",i,j);
            return;
        }
    
        (*cnt)++;
        printf("---bg --- %d ---- %d \n",i,j);
        if ( i < 50 && j < 50 ) {
            f(i+1,++j,cnt);
            f(i+1,++j,cnt);
        }
    }
    

    Still a lot of recursion but without the danger of not stopping.

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

Sidebar

Related Questions

I've been struggling with this for hours, but I couldn't manage to find out
im struggling with syntax here: hopefully this question is v simple, im just miising
I'm struggling to find the right terminology here, but if you have jQuery object...
So I thought this should be easy, but, I'm struggling here... Here's my code:
I'm struggling with this problem for a day now, and I just can't figure
I've been struggling with this for a good while now. I'm trying to determine
I'm really new to Ruby (first day!) and I'm struggling with this here. I'm
I am being struggling with this regex expression long time but i cannot find
Apologies about this simple question. Still struggling with some of the memory concepts here.
Hey everyone. I'm really struggling to figure out the logic with this one and

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.