Skip navigation

A simple template, to find the minimum of 3 numbers.

Can you find the bug in this code?

  template<typename T> inline T min3( const T& a, const T& b, const T& c )
  {
    if( a < b && a < c )  return a ;
    else if( b < a && b < c ) return b ;
    else return c ;
  }

Hint: Actually I’m not going to give you any hints. But it is possible for the above function to return the incorrect value.

Advertisements

One Comment

  1. Wrong value will be returned for input, where a = b && a < c (eg. a = 1, b = 1, c = 2)


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: