Why does strlen not working for me?

Posted by tushar on Stack Overflow See other posts from Stack Overflow or by tushar
Published on 2010-04-09T16:26:02Z Indexed on 2010/04/09 16:43 UTC
Read the original article Hit count: 221

Filed under:
|
char p[4]={'h','g','y'};
cout<<strlen(p);

This code prints 3.

char p[3]={'h','g','y'};
cout<<strlen(p);

This prints 8.

char p[]={'h','g','y'};
cout<<strlen(p);

This again prints 8.

Please help me as I can't figure out why three different values are printed by changing the size of the array.

© Stack Overflow or respective owner

Related posts about c++

Related posts about string