Can not explain output of simple string operation in C -


this code:

    #include<stdio.h>     #include<string.h>     int main()     {        char *s = "name";        int n = strlen(s);        int i;        s = &s[n+1];        for(i=0; i<=n; i++)        {           printf("%d %c",i,*s);           s++;        }          return 0;     } 

output:

0 %1 d2  3 %4 c 

i unable understand output. why printing % although there's no escape sequence.

this line s = &s[n+1]; causing pointer point off middle of nowhere. after start reading random garbage it. apparently random garbage includes % characters.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -