replied!
Bart Wrote:
> On May 6, 11:45 am, "Kevin" <yushuma...@[EMAIL PROTECTED]
> wrote:
> > Source:
> > #include <stdio.h>
> > #include <ctype.h>
> > void main()
> > {
> > char a[]="this is the beautiful world!";
> > char b[20];
> > strcpy(b,a);
> > printf("char array b size is(%d),The content of b
is:%s\n",sizeof(b),b);
> > if(strcmp(a,b)==0)
> > printf("a equal to b!\n");
> >
> > }
> >
> > Now , question as follows:
> >
> > 1. Why "b" size unequal "a" size , but "b" can output "a" content?
> > 2. Why "if(strcmp(a,b)==0)" is true?
>
> a and b are different types:
>
> a is a pointer to a string
> b /is/ a string.
>
> But a can obviously point to a string identical to what's in b.
>
> The size of a will be 4 or whatever, the size of b will be 20
> (although it should be more in this case otherwise your "this is..."
> string will overflow it).
>
> strcmp() compares two pointers to strings; but b is automatically
> converted to such a pointer, thanks to the way C handles arrays.
>
> --
> Bartc


|