Here if i give namangarg as input it is able to print every char even though the size of char array is 5 only?

#include
using namespace std;
int main()
{
char ch[5];
cin>>ch;
cout<<ch;
return 0;
}

hello @namangarg31
compiler always looks for \0 to stop printing (when it prints char array/char *).
when u are entering namangarg cleary \0 is not there till the end so namangarg will print for sure but it might possible that \0 is not present even after g(talking about last g) so u might see some garbage vaue as well

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.