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

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -