Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

A few C functions I need help with

Name: OP 2012-04-30 4:57

These are pretty trivial, but I am no programmer.


if I do swap( 4, 6 )

where

int swap( int x, int y) {
   x = y;
   y = x;
   return( y );
}

What will it return and why?

Name: OP 2012-04-30 11:00

Thank you for the explanation and I am especially grateful for the improved version.

Since there is int before swap, the returned 6 would be considered integer, correct?

What purpose does the void type serve in the improved (and also working) version of swap?

Now, onto the next one:

int excl( int n ) {
  if ( n == 1 ) return 1;
  return n * excl( n - 1 );
}

I'm pretty sure this is just a function to compute factorial. The problem is what happens, when 0 (or negative number) is on the input. Will it result in an infinite loop? If so, how to prevent this and make it correctly output excl(0) as 1?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List