<p>Why does <code>n</code> not equal to <code>8</code> in the following function?</p>

<pre><code>void foo(char cvalue[8])
{
  int n = sizeof (cvalue);
}
</code></pre>

<p>But <code>n</code> <em>does</em> equal to <code>8</code> in this version of the function:</p>

<pre><code>void bar()
{
  char cvalue[8];
  int n = sizeof (cvalue);
}
</code></pre>

[{'answer_id': 49055, 'author': 'Nick Retallack', 'author_id': 2653, 'author_profile': 'https://Stackoverflow.com/users/2653', 'pm_score': 7, 'selected': True, 'text': "<p>Because you can't pass entire arrays as function parameters in C.  You're actually passing a pointer to it; the brackets are syntactic sugar.  There are no guarantees the array you're pointing to has size 8, since you could pass this function any character pointer you want.</p>\n\n<pre><code>// These all do the same thing\nvoid foo(char cvalue[8])\nvoid foo(char cvalue[])\nvoid foo(char *cvalue)\n</code></pre>\n"}, {'answer_id': 49061, 'author': 'dagorym', 'author_id': 171, 'author_profile': 'https://Stackoverflow.com/users/171', 'pm_score': 1, 'selected': False, 'text': "<p>In the first example, cvalue as passed parameter is in really just a pointer to a character array and when you take the <code>sizeof()</code> of it, you get the size of the pointer. In the second case, where you've declared it as a local variable, you get the size of the the entire array.</p>\n"}, {'answer_id': 49129, 'author': 'hoyhoy', 'author_id': 3499, 'author_profile': 'https://Stackoverflow.com/users/3499', 'pm_score': 0, 'selected': False, 'text': '<p>The size of the parameter on 32-bit systems will be 4 and on 64-bit systems compiled with -m64 will be 8.  This is because arrays are passed as pointers in functions.  The pointer is merely a memory address.</p>\n'}, {'answer_id': 49656, 'author': 'DrPizza', 'author_id': 2131, 'author_profile': 'https://Stackoverflow.com/users/2131', 'pm_score': 4, 'selected': False, 'text': '<p>C and C++ arrays are not first class objects; you cannot pass arrays to functions, they always decay to pointers.</p>\n\n<p>You can, however, pass pointers and references to arrays. This prevents the array bounds from decaying.  So this is legal:</p>\n\n<pre><code>template&lt;typename T, size_t N&gt;\nvoid foo(const T(&amp;arr)[N])\n{\n    int n = sizeof(arr);\n}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/49046', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5065/']