title: Why am I unable to cast void pointers inside my search function?
body: <p>I am trying to solve a problem in which I need to implement a function that receives a void pointer as an argument. This function needs to search an array for a specific value and return a pointer to the value.</p>
  <p>The *arr == *val comparison statement produces a &quot;Invalid operands to binary expression ('void' and 'void')&quot; when I run the following code. I have not been able to figure out why.</p>
  <pre><code>void* search(void *arr, int n, void* val, char c){
      if(c == 'c') {
          arr = (char*) arr;
          val = (char*) val;
      } else if(c == 'i'){
          arr = (int*) arr;
          val = (int*)val;
      } else {
          arr = (float*)arr;
          val = (float*)val;
      }
      for (int i = 0; i &lt; n; i++) {
          if(*arr == *val){
              return arr;
          } else {
              arr++;
          }
          return NULL;
      }
  }
  </code></pre>