C - Why does this output "%s" -


char *x = "world"; x = &x[6];   printf("%s", x); 

hi can't understand why above code outputting first argument in printf statement. if change printf("f%s",x); outputs "ff%s" why output ff twice?

thanks

because reading beyond array boundary. array of length 6 (0-5) , you're accessing 6th member (your last available 5th). undefined operation , unpredictable things print out portion of printf statement.


Comments

Popular posts from this blog

java - Solr query version issue: Invalid version or the data in not in 'javabin' format -

Hard vs. Soft Water: What's The Difference?

The Ten Most Livable Cities In The World