Im really confused, I had this recursive add function working but my teacher wants us to be able to use ++ instead of + 1... anyone know why im getting a segmentation fault on this, i feel like this is a really dumb mistake.

int add( int n, int m ){

  if( m == 0 ) return( n ) ;

  return( add( n++, m-- ) ) ;

}

Recommended Answers

All 2 Replies

You need to use the prefix form of ++ and --. So: return( add( ++n, --m ) ) ;

thanks, that was really annoying me

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.