When and why would i use abs in c++
<p>So, I was looking at some open source code that searches through a random set of numbers to find the closest number to 0. And for some reason it uses abs in the  library a bit, and I was wondering when why and where I would use it. Here is the code.</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;vector&gt;
#include &lt;cmath&gt;

using namespace std;

int main()
{
  int N; // the number of temperatures to analyse
  cin &gt;&gt; N; cin.ignore();

  if( N == 0 ) {
        cout &lt;&lt; 0 &lt;&lt; endl;
        return 0;
    }

    int bestTemp = 5527;
    for( int i = 0; i &lt; N; i++ ) {
        int v;
        cin &gt;&gt; v;
        if( abs( v ) &lt; abs( bestTemp ) ) {
            bestTemp = v;
        } else if( abs( v ) == abs( bestTemp ) &amp;&amp; bestTemp &lt; 0 ) {
            bestTemp = v;
        }
    }


    // Write an action using cout. DON'T FORGET THE "&lt;&lt; endl"
    // To debug: cerr &lt;&lt; "Debug messages..." &lt;&lt; endl;

    cout &lt;&lt; bestTemp &lt;&lt; endl;
  return 0;
}
</code></pre>

<p>I got this code from codingame and the user I found this from was Bob.
P.S I am pretty young so could you make it easier for me to understand, please and thank you.</p>