How to get the length of an array in c++?
<p>I tried to write my own function for this, but I get wrong result</p>

<pre><code>#include &lt;iostream&gt;

using namespace std;

template&lt;typename T&gt;
int array_length(T v[]) {
    return (sizeof v)/sizeof(T);
}

int main() {
    int v[] = {1, 2, 3, 4};
    cout &lt;&lt; array_length(v) &lt;&lt; endl;
    return 0;
}
</code></pre>
