First: Writing this article stems from my discussion on ' the ' and '
When I'm on char a []=];
int size_a=sizeof (a); Result is 2
I was wondering if the string ended with ' m ', and I tested it again:
Char a[]= "b\0";
Cout<<sizeof (a); Result is 3
Test again:
Char a[]= "\0\0\0";
Cout<<sizeof (a); Result is 4
Final Test:
Char a[]= "";
Cout<<sizeof (a); Result is 1
The test found in the string is the system automatically added, and regardless of whether you have the original string;
Second:
Example one: int main (int argc, char *argv[])
{char str[] = {' H ', ' e ', ' l ', ' l ', ' o '};
Char bb[]={
' A ', ' B ', ' C ', ' D '
};
cout<<bb<<endl;
The output is as follows: Note that the character after the last 0 of each run of the output will be different
Example two: int main (int argc, char *argv[])
{char str[] = {' H ', ' e ', ' l ', ' l ', ' o '};
Char bb[]={
' A ', ' B ', ' C ', ' D '
};
cout<<str<<endl;
Output results
Why is the result of graph one output abcdhello* (* number denotes random character)? We can extrapolate a stack-based storage structure, so the pre-stack test defined in the function is
Example three:
int main (int argc, char *argv[])
{char str[] = {' H ', ' e ', ' l ', ' l ', ' o '};
Char bb[]={
' A ', ' B ', ' C ', ' D '
};
Char cc[]={
' A ', ' B '
};
cout<<cc<<endl;
Output results such as:
And then we're going to talk about a random number at the end.
int main ()
{
Char str[] = {' H ', ' e ', ' l ', ' l ', ' o '};
Char bb[]={' A ', ' B ', ' C ', ' D '};
Char cc[]={' A ', ' B '};
bb[7]= ' + ';
cout<<bb<<endl;
As a result, if you have a b[7]= ' ", then the output ends at seventh after BB
The above test was tested in MinGW gcc version3.2, using cfree, note that I used VS2010 test results are not the same AH
Test
Address high place at the bottom of the stack, output, such as Output cc bar, AB hot iron ABCD hot a few, and then hello in the hot a few final output also ended, as for the end, I will explore ING
Hope Daniel Treatise!
C + + character array and string disclosure