Explain the output please....? | SoloLearn: Learn to code for FREE!


Explain the output please....?


6/29/2020 4:41:56 PM


12 Answers

New Answer


Samanvitha P R yeah am getting same output


Martin Taylor thanks for explanation i understood very well


Samanvitha P R but why its printing @


char x[]="%s Kritika"; printf (x,x); is the same as... printf("%s Kritika", "%s Kritika"); The first sting is the format specifier. The second string is an argument for the formatter to operate upon. The format specifier reads "print the string in the arguments, a space, then the word Kritika". Since the string in the arguments is "%s Kritika" it prints "%s Kritika" + " Kritika" which results in "%s Kritika Kritika".


Samanvitha P R sorry i understood because size was less so its printing garbage now i increased the length then its printing properly but why %s not printing two times


Dennis yes i understood but wht %s not printed two times


Dennis ohh i understood thanks


Because the first parameter of printf is a format specifier which replaces the formats "%s" in this case with the 2nd and so on parameters. ( even if you don't provide one, so be careful there ) The 2nd parameter and so on don't have this behaviour.


Your character array is not big enough to include the null character so anything can happen when it tries to print it.


Martin Taylor your explanation is very clear man . Thank you.