Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat's the difference between char[] and char[10] in C++?
    text
    copied!<p>Is there any difference between char[] and char[10] (or any other arbitrary constant)?</p> <p>for example:</p> <pre><code>char[] = "here"; char[10] = "there"; </code></pre> <p>When I ran such a program:</p> <pre><code>struct TreeNode { struct TreeNode* left; struct TreeNode* right; char elem; }; void BinaryTreeFromOrderings(char* ,char* ,int); int main() { char a[] = ""; char b[] = ""; cin &gt;&gt; a &gt;&gt; b; BinaryTreeFromOrderings(b, a, strlen(a)); return 0; } void BinaryTreeFromOrderings(char* inorder, char* preorder, int length) { if(length == 0) return; TreeNode* node = new TreeNode; node-&gt;elem = *preorder; int rootIndex = 0; for(;rootIndex &lt; length ; rootIndex ++) { if(inorder[rootIndex] == *preorder) break; } //left BinaryTreeFromOrderings(inorder,preorder+1,rootIndex); //right BinaryTreeFromOrderings(inorder + rootIndex +1 ,preorder + rootIndex +1,length - (rootIndex + 1)); cout &lt;&lt; node-&gt;elem; delete [] node; return; } </code></pre> <p>The result seems right, but the program will dump just before exit.</p> <p>Then I made an experiment:</p> <pre><code>int main() { char a[] = ""; cin &gt;&gt; a; cout &lt;&lt; a; return 0; } </code></pre> <p>It will run successfully when I input less than 9 characters. (gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5))</p> <p>And if i initialize a[] with:</p> <pre><code>char a[] = "123456789"; </code></pre> <p>It will success less than 25 charactres.</p> <p>I guess there's something that compiler cannot determine the size of a. But what's the detailed reasons?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload