Wrong output? PLease explain my mistake in code

the way you have use will work on character array only not on strings

Modified Code

Sir, Reason? …

the reason is working of cout

cout<<x;

if x is character array then it print till ‘\0’
but if it is string it will print the whole string according to size of string

to understand better run this code

Code

Ohh okay thank you sir!!

i hope this help and your doubt is resolved
if you have more doubts regarding this feel free to ask
if your doubt is resolved mark it as resolved from your doubt section inside your course