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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:50:24+00:00 2026-06-13T09:50:24+00:00

This is the function that multiplies a and b : 0 int mult(int a,

  • 0

This is the function that multiplies a and b:

0    int mult(int a, int b){
1      if(a==0){
2        return 0;
3      } else{
4        a=a-1;
5        int c = mult(a,b);
6        int d = b + c;
7        return d;
8      }
9    }

I am playing with arguments 2 and 3: the result is 6, but why?

In line 5 I will get 0 after the second a=a-1; and then d is 3 then return 3 and not 6. Am I stupid or is it also confusing for you?

  • 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-13T09:50:25+00:00Added an answer on June 13, 2026 at 9:50 am

    Let’s go step by step [ mult(2, 3) ]: –

     1. (a = 2, b = 3) : - 
         a = 1;
         c = mult(1, 3); ---->    2. (a = 1, b = 3) : - 
                                      a = 0;
                                      c = mult(0, 3); -----> 3. (a = 0, b == 3) : -
                                                                 return 0
    ---------------------------------------------------------------------------------
                                      c = 0;
                                      d = (b + c) = 3;
                                      return 3; 
    ------------------------------------------------------------------
         c = 3;
         d = b + c == 3 + 3 = 6
    
         return 6;
    

    NOTE: –

    States of recursive calls are stored on stack. So, as the base condition is reached, the stack starts unwinding, passing the result of the current call to the previous call, thus reaching the state where it started with a final result.

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

Sidebar

Related Questions

I want to create a function that get vector<int> run over all his elements
Is it possible that when calling multiple times this function: void Func(String spr, PictureBox
So I wrote this function that is given possible numbers, and it has to
I have this function that I would like to condense into some iterator. How
I am using this function (that I found on this forum) to calculate the
Hi am using this function that works by a single ID ( 52000121 )
So I have this function that forks N number of child processes. However it
I have this function that prints the name of all the files in a
I have this function that converts all special chars to uppercase: function uc_latin1($str) {
I have this function that takes the input of a, runs a calculation 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.