title: Get count of an array from within a function
body: <p>I'm trying to write a function that prints the elements of a given array. However, I don't understand how I can count the elements of the array which is passed into my function. Here's the code:</p>
  
  <p>In this example, I am trying to get the count from within my function, though this only returns 1.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  void first_function(int ages[], char *names[]) {
      int i = 0;
      int count = sizeof(*ages) / sizeof(int);
      for(i = 0; i &lt; count; i++) {
          printf("%s has lived %d years.\n", names[i], ages[i]);
      }
  }
  
  int main(int argc, char *argv[])
  {
      int ages[] = { 7, 32, 36 };
      char  *names[] = {
          "Tiger", "Sandy",
          "Ryan"
      };
  
      first_function(ages, names);
      printf("---\n");
  
      return 0;
  
  }
  </code></pre>
  
  <p>In this example, I give the function an extra parameter (count), then get the count from within main. Is this the normal way to do it? It seems unclean somehow.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  void first_function(int ages[], char *names[], int count) {
      int i = 0;
      for(i = 0; i &lt; count; i++) {
          printf("%s has lived %d years.\n", names[i], ages[i]);
      }
  }
  
  int main(int argc, char *argv[])
  {
      int ages[] = { 7, 32, 36 };
      char  *names[] = {
          "Tiger", "Sandy",
          "Ryan"
      };
  
      int count = sizeof(ages) / sizeof(int);
  
      first_function(ages, names, count);
      printf("---\n");
  
      return 0;
  
  }
  </code></pre>