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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:46:14+00:00 2026-06-09T11:46:14+00:00

I really can’t understand this code. When a function calls itself what really happens?

  • 0

I really can’t understand this code. When a function calls itself what really happens? It is related to the concept of stack, I know, but still I can’t solve these questions.

#include<stdio.h>

fun(int);

main()
{
  int x=3;
  fun(x);
}

fun(int a) 
{
  if(a<0)
   {
     fun(--a);    // what happens when function calls itself
     printf("%d",a);
     fun(--a);
   }
} 

Please explain the sequence of events which occur during this.

  • 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-09T11:46:15+00:00Added an answer on June 9, 2026 at 11:46 am

    Functions are merely code that resides somewhere in memory. Whenever you make a function call, the compiler translates that into an assembly code command for the platform that saves the address of the next command to be executed after the function call is complete as well as tell the processor where to literally “jump” in memory in order to read the next command to be executed.

    Recursion works because you can easily tell the processor to “jump” back to the beginning of the function’s code block in memory. The current function that you are calling from has a memory address just like any other function, and therefore there is no difference for the processor to jump to the beginning of the current function’s code block in memory, or some other function’s code block in memory.

    The stack comes into play due to the fact that we need to save the return address for the command to execute after we complete the function call, as well as a location to store the current function’s arguments and automatic variables. So as you make successive function calls, there is a call-stack that is created, with arguments as well as return addresses for any previously called functions higher-up on the stack if the stack is growing downwards. This is collectively called the “stack frame” for the function. When you return from a function, the current function’s stack frame is popped off the bottom of the stack, and then the memory address for where the processor needs to jump back to after the function is complete is read and executed. In the case of recursion, this means that we simply jump back to a previous version of the same function, but in this case the automatic stack variables and arguments will be different after we return since we have returned back to a stack frame for a previous version of the function.

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

Sidebar

Related Questions

I try to parse encrypted &RQ history, but i really can't understand asm code.
I know this subject was discussed here, but I really can't get this to
I am getting this error and I really can't understand why. The code: b1.setOnClickListener(new
I do understand how Stack() and Stack<T> works, but I really can't see any
I really can't understand how the below piece of code is working... options.each {
I'm trying to understand amazon php sdk for AWS but I really can't use
Well, I don't know if I'm completely wrong, but I really can't find a
I know it's a simple question but I really can't find anything on Google.
I really can't understand why this statement is wrong $uname=$_POST['username']; $pass=$_POST['pass']; $str=select * from
I really can not understand this problem. When i publish my asp.net 4.0 website

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.