"Sanjeev" <> wrote in message
news: om...
> Output of followin program at Turbo C++ 3.0 is 7 ( Not 2 or 3).
>
> Please explain why ?
>
> ////////////////////////////////////////////////
> #include<stdio.h>
> #include<string.h>
>
> void main()
> {
> char ch[]={'a','b'};
>
> int len;
> len=strlen(ch);
>
> printf("%d\n",len);
> }
> ////////////////////////////////////////////////
This is actually undefined, since ch is an array of chars but is not null
terminated, if you had
char ch[] = "ab";
or
char ch[] = {'a','b','\0'};
then this would be fine and you would get your expected result
Allan
|