>> char a[3]="mnnitald"; "mnnitald" is string literal and causes allocation of static storage. char a[3] leads to allocation of memory where first three characters of mnnitald are copied a[3] doesn't include the terminating character for a string. which means strlen has to read beyond the bounds of array a and hence you get random answers.
On Jul 27, 9:08 pm, Shantanu Sachdev <[email protected]> wrote: > #include<stdio.h> > #include<string.h> > int main() > { > char a[3]="mnnitald"; > int x=strlen(a); > printf("%d",x); > > } > > Plz xplain the output of this program. x comes out to be 7. if u take > a[2],den it comes to be 6 nd so on.and if a[7] is taken, size comes out to > be 10. > Compiler - GCC. > -- > SHANTANU SACHDEV > 20098080 > MNNIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
