Doubt in '\n' vs '\0'

I have commented a part in my code please check and explain.

What wrong with code??

Now to Rectify it : β€œwhat can we do???”

Modified Code:

one way:
(it will not evaluate \n)

cin.getline(arr,101,'\n');

    ch=arr[0];

    while(arr[i]!='\0') // taking \0 here, makes my code working.. please explain

    {

other way:
(it will evaluate \n as well )

   cin.getline(arr,101,'\0');
    ch=arr[0];

    while(arr[i]!='\0') // taking \0 here, makes my code working.. please explain

    {

i hope this helps,
if you have further doubt feel free to ask

1 Like

Such a wonderful explanation. That means at the end of character array or string compiler itself inserts β€˜\0’?

yes,
bcz string is a character array terminated with β€˜\0’

1 Like

Thanks a lot. Wonderful explanation by you.

i am resolving your doubt,
plz give your valuable feedback

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.