Click here to Skip to main content
15,917,702 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Editbox in FormView Pin
CosminU1-Apr-07 23:35
CosminU1-Apr-07 23:35 
Questionasking how to program list only hidden files under linux in c Pin
Arif Liminto31-Mar-07 7:15
professionalArif Liminto31-Mar-07 7:15 
QuestionLinux? Pin
CPallini31-Mar-07 8:20
mveCPallini31-Mar-07 8:20 
AnswerRe: asking how to program list only hidden files under linux in c Pin
ThatsAlok1-Apr-07 21:18
ThatsAlok1-Apr-07 21:18 
QuestionHTF? :mad: Pin
_808631-Mar-07 6:53
_808631-Mar-07 6:53 
AnswerRe: HTF? :mad: Pin
PJ Arends31-Mar-07 7:20
professionalPJ Arends31-Mar-07 7:20 
GeneralRe: HTF? :mad: [modified] Pin
_808631-Mar-07 7:58
_808631-Mar-07 7:58 
GeneralRe: HTF? :mad: Pin
PJ Arends31-Mar-07 12:07
professionalPJ Arends31-Mar-07 12:07 
_8086 wrote:
but why does it bypass this condtion when n =0, or -1

It does not, the recursive function calls stop when n is zero or less.

I think your confusion is coming from what n is. You have to remember that a new n is created every time fun() is called, you are not using a single n.

I cleaned up your sample a bit, so lets step through it:
void fun(int n)                              // start with n = 3
{
   if (n > 0)                                // n is greater than zero
   {
      fun(--n);                              // n is now two, recursive call to fun(2)

        +void fun(int n)                     // start with n = 2
        |{
        |   if (n > 0)                       // n is greater than zero
        |   {
        |      fun(--n)                      // n is now one, another recursive call to fun(1)
        |
        |         +void fun(int n)           // start with n = 1
        |         |{
        |         |   if (n > 0)             // n is greater than zero
        |         |   {
        |         |      fun(--n)            // n is now zero, another recursive call to fun(0)
        |         |
        |         |         +void fun(int n) // start with n = 0;
        |         |         |{
        |         |         |   if (n > 0)   // n is not greater than zero
        |         |         |   {
        |         |         |      fun(--n)  // not called
        |         |         |      printf("%d\n", n);
        |         |         |   }
        |         |         +}               // exit fun()
        |         |
        |         |      printf("%d\n", n);  // n is zero - output "0"
        |         |   }
        |         +}                         // exit fun()
        |
        |      printf("%d\n", n);            // n is one - output "1"
        |   }
        +}                                   // exit fun()

      printf("%d\n", n);                     // n is two - output "2"
   }
}                                            // exit fun()
and repeat ad infinitum.



You may be right
I may be crazy
-- Billy Joel --


Within you lies the power for good, use it!!!

GeneralRe: HTF? :mad: Pin
_808631-Mar-07 16:49
_808631-Mar-07 16:49 
GeneralRe: HTF? :mad: Pin
CPallini31-Mar-07 12:08
mveCPallini31-Mar-07 12:08 
GeneralRe: HTF? :mad: Pin
_808631-Mar-07 16:51
_808631-Mar-07 16:51 
QuestionChttpConnection class problem Pin
prithaa31-Mar-07 6:31
prithaa31-Mar-07 6:31 
AnswerRe: ChttpConnection class problem Pin
Mark Salsbery1-Apr-07 7:10
Mark Salsbery1-Apr-07 7:10 
GeneralRe: ChttpConnection class problem Pin
prithaa1-Apr-07 20:09
prithaa1-Apr-07 20:09 
GeneralRe: ChttpConnection class problem Pin
Mark Salsbery2-Apr-07 4:21
Mark Salsbery2-Apr-07 4:21 
GeneralRe: ChttpConnection class problem Pin
prithaa2-Apr-07 19:21
prithaa2-Apr-07 19:21 
GeneralRe: ChttpConnection class problem Pin
Mark Salsbery3-Apr-07 7:09
Mark Salsbery3-Apr-07 7:09 
GeneralRe: ChttpConnection class problem Pin
prithaa4-Apr-07 21:50
prithaa4-Apr-07 21:50 
Questionmemory problem Pin
vasu_sri31-Mar-07 3:01
vasu_sri31-Mar-07 3:01 
AnswerRe: memory problem Pin
CPallini31-Mar-07 5:31
mveCPallini31-Mar-07 5:31 
Questionimapi.h for ICDBurn Pin
scoobydoo200731-Mar-07 2:59
scoobydoo200731-Mar-07 2:59 
AnswerRe: imapi.h for ICDBurn Pin
kanduripavan3-Apr-07 23:00
kanduripavan3-Apr-07 23:00 
Questionis an ip address enough Pin
prithaa31-Mar-07 2:32
prithaa31-Mar-07 2:32 
AnswerRe: is an ip address enough Pin
ThatsAlok1-Apr-07 21:16
ThatsAlok1-Apr-07 21:16 
GeneralRe: is an ip address enough Pin
prithaa1-Apr-07 23:35
prithaa1-Apr-07 23:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.