help needed with K&R code on p. 87

From: Buck Rogers (who_at_cares.com.au)
Date: 02/29/04


Date: Sun, 29 Feb 2004 18:42:23 +1100

Hi guys!

Here's the code:
===============
#include <stdio.h>

/* printd: print n in decimal */
void printd(int n)
{
     if (n < 0) {
         putchar('-');
         n = -n;
     }
     if ( n / 10)
         printd(n / 10);
     putchar(n % 10 + '0');
}
=================
1. What is the value of if ( n / 10)? I don't understand this condition
at all. I assume the condition has to be true otherwise the function would
do
nothing. But what makes it true?

So I create my own main to test the above function:
================
#include <stdio.h>

void printd(int n);

int main(void)
{
     int n = 123;

     printd(n);
     return 0;
}
===================

2. The output I get is 123, but I am not really sure how the recursion
works
in the function - I find K&R explanations are very short and cryptic. Can
someone
please explain?

Thanks in advance!

Buck

-- 
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/