0

what's the difference between these two.

int find_set ( int v ) { if ( v == parent [ v ] ) return v ; return parent [ v ] = find_set ( parent [ v ] ) ; } 

And:

int find_set ( int v ) { if ( v == parent [ v ] ) return v ; parent [ v ] = find_set ( parent [ v ] ) ; } 
1
  • 6
    The second doesn't have a return statement if the if statement fails. Is that what you meant? Commented Dec 27, 2012 at 23:18

1 Answer 1

4

The difference, as stated by @Omri, is that the second has no return if the if statement does not execute, leaving you with (hopefully) a compiler error for a code path with no return value. Unlike languages like Ruby, the last statement of a C++ method or function is not implicitly the return value.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.