title: Calculate Length of Array in C by Using Function
body: <p>I want to make a FUNCTION which calculates size of passed array.</p>
  
  <p>I will pass an Array as input and it should return its length. I want a Function</p>
  
  <pre><code>int ArraySize(int * Array   /* Or int Array[] */)
  {
     /* Calculate Length of Array and Return it */
  
  }
  
  void main()
  {
    int MyArray[8]={1,2,3,0,5};
    int length;
  
    length=ArraySize(MyArray);
  
    printf("Size of Array: %d",length);
  
  }
  </code></pre>
  
  <p>Length should be 5 as it contains 5 elements though it's size is 8
  (Even 8 will do but 5 would be excellent)</p>
  
  <p>I tried this:</p>
  
  <pre><code>int ArraySize(int * Array)
  {
  
    return (sizeof(Array)/sizeof(int));
  
  }
  </code></pre>
  
  <p>This won't work as "<code>sizeof(Array)</code>" will retun size of Int Pointer.
  This "<code>sizeof</code>" thing works only if you are in same function.</p>
  
  <p>Actually I am back to C after lots of days from C# So I can't remember (and Missing <code>Array.Length()</code>) </p>
  
  <p>Regards!</p>