title: How to check if int variable has been set?
body: <p>Lets say I have a variable <code>num</code>.</p>
  
  <p>Before I can evaluate an <code>if</code> statement, I need to check if this variable has been set in the first place. Typically I would use either <code>-1</code>, <code>0</code> or <code>math.MaxInt32/math.MinInt32</code> but for this task I need to check if my program has set its value.</p>
  
  <p>I tried <code>nums := nil</code> and in my <code>if</code> statement I had something like <code>if nums == nil || ...</code>.</p>
  
  <p>But when creating the <code>nums</code> variable I was surprised to get the error <code>cannot convert nil to type int</code>. How I can achieve what I want to do?</p>
  
  <p>To make it clear: This is a leetcode <a href="https://leetcode.com/problems/third-maximum-number/description/" rel="nofollow noreferrer">question</a> and don't have control of the inputs, they put all sorts of numbers inside include math.MaxInt32, math.MinInt32</p>
  
  <p>Full code:</p>
  
  <pre><code>func thirdMax(nums []int) int {
  
      dict := make(map[int]int, 0)
  
      varmaxOne := math.MinInt32
      maxTwo := math.MinInt32
      maxThree := math.MinInt32
  
  
      for _, value := range nums {
  
          if value &gt;= maxOne &amp;&amp; dict[value] &lt; 1 {
  
              maxThree = maxTwo
              maxTwo = maxOne
              maxOne = value
  
          }else if value &gt;= maxTwo &amp;&amp; dict[value] &lt; 1{
              maxThree = maxTwo
              maxTwo = value
          } else if value &gt;= maxThree &amp;&amp; dict[value] &lt; 1 {
              maxThree = value
          }
  
          dict[value] += 1
      }
  
      if maxThree == math.MinInt32 {
          return maxTwo
      }
      return maxThree
  
  }
  
  func max(a int, b int) int {
      if a &gt; b {
          return a
      }
      return b
  }
  </code></pre>
  
  <p>Test</p>
  
  <pre><code>func TestThirdMax(t *testing.T) {
      //array := []int{2, 3, -1, -9, 11, 4, 3, 0, -100}
      //array := []int{2, 2, 3, 1}
      array := []int{1,2,-2147483648}
      //array := []int{3,2,1}
      result := thirdMax(array)
  
      if result != 2 {
          t.Errorf("Expected 2, but it was %d instead.", array)
      }
  }
  </code></pre>
  
  <p>The code above use <code>math.MinInt32</code>, but fails with the input given. The idea was to have <code>nil</code> instead and put a check in the <code>if</code> statement, but fails as stated above.</p>