When we put the input as C.name[0]=‘B’ , C.name[1]=‘M’, C.[2]=‘W’ where C is object and array is of size 20 (Name[20]…after giving the command to print why doesn’t it print the whole array including it’s garbage value?Instead it prints just BMW.
Character data type array
bhaiya has added a ‘\0’ ( null ) character which signifies the end of the input character
that is also the reason when we iterate through a char array
we write the condition of
ch[i] !=’\0’
as soon as null character is encountered the loop gets out of that iteration
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.