title: Array Initialization Function: Passing Array as Pointer: C++
body: <p>I'm trying to initialize arrays by passing them to an initialization function as a pointer. My program compiles with no errors, but when I run it; it prints out Character Count and stops.</p>
  
  <p>This is what I have so far:</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;cctype&gt;
  #include&lt;string&gt;
  #include&lt;iomanip&gt;
  
  using namespace std;
  
  void initialize(int *array, int n, int value);    
  
  int main()
  {
   char ch;
   int punctuation, whitespace, digit[10], alpha[26]; 
  
   punctuation = 0, whitespace = 0;
  
  initialize(digit, sizeof(digit)/sizeof(int), 0);
  initialize(alpha, sizeof(alpha)/sizeof(int), 0);
  
  while(cin.get(ch))
  {
      if(ispunct(ch))
          ++punctuation;
      else if(isspace(ch))
          ++whitespace;
      else if(isdigit(ch))
          ++digit[ch - '0'];
      else if(isalpha(ch))
      {
          ch = toupper(ch);
          ++alpha[ch - 'A'];
      }
  
      if(whitespace &gt; 0)
      {
          cout &lt;&lt; "Whitespace = " &lt;&lt; whitespace &lt;&lt; endl;
      }
  
      if(punctuation &gt; 0)
      {
          cout &lt;&lt; "Punctuation = " &lt;&lt; punctuation &lt;&lt; endl;
      }
  
      cout &lt;&lt; setfill('-') &lt;&lt; setw(17) &lt;&lt; '-' &lt;&lt; setfill(' ') &lt;&lt; endl;
      cout &lt;&lt; " Character " &lt;&lt; " Count " &lt;&lt; endl;
      cout &lt;&lt; setfill('-') &lt;&lt; setw(17) &lt;&lt; '-' &lt;&lt; setfill(' ') &lt;&lt; endl;
  
  
      return 0;
   }
  }
  
  void initialize(int *array, int n, int value)
  {
    int i;    
  
    for (i = 0; i &lt; n; ++i)
    {
       value += array[i];
    }
  }
  </code></pre>
  
  <p>I'm not sure that I am doing anything wrong here. Although, I am a bit confused as to how pointers work after they have been passed to another function. Can someone explain?</p>
  
  <p>Thank you</p>