3 Replies - 412 Views - Last Post: 20 July 2011 - 04:41 AM Rate Topic: -----

#1 raghu1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 20-July 11

how does ths code work? preincrement and predecrement as parameters

Posted 20 July 2011 - 12:16 AM

How does ths code work? preincrement and predecrement as parameters

#include<stdio.h>
#include<conio.h>
#include<process.h>
void fun(int);
void main()
{
 int a;
clrscr();
a=3;
fun(a);
getch();
}
void fun(int n)
{
 if(n>0)
 {
    fun(--n);
    printf("%d",n);
    fun(--n);
  }
}


This post has been edited by stayscrisp: 20 July 2011 - 02:00 AM
Reason for edit:: Please use code tags!!

Is This A Good Question/Topic? 0
  • +

Replies To: how does ths code work? preincrement and predecrement as parameters

#2 PlasticineGuy  Icon User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

Re: how does ths code work? preincrement and predecrement as parameters

Posted 20 July 2011 - 01:13 AM

What does the code do? What output are you expecting? I get 0120.

This post has been edited by PlasticineGuy: 20 July 2011 - 01:13 AM

Was This Post Helpful? 0
  • +
  • -

#3 oscode  Icon User is offline

  • D.I.C Regular

Reputation: 109
  • View blog
  • Posts: 257
  • Joined: 24-October 10

Re: how does ths code work? preincrement and predecrement as parameters

Posted 20 July 2011 - 02:07 AM

There is no pre-increment operator used in this code. Get a pen and paper, trace through it by hand and write down what's happening.
Was This Post Helpful? 1
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,495
  • Joined: 23-August 08

Re: how does ths code work? preincrement and predecrement as parameters

Posted 20 July 2011 - 04:41 AM

Search Google for recursion.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1