what will be the output if i dont write null character?
because it is giving the same input to in my pc.
What if i dont write null character?
about which code your are taking
because in the video on which you have asked doubt
there is not such thing
this is my code. it works same with or without the null character. that is why i am asking that if null character does not play any role then why do we need to use it?
this code is correct
where you want to put NULL?
no sir. i am asking that as prateek sir told in the video that if we don’t put NULL at the end of initialization of an array it always gives us a garbage value. but in my code i have not given NULL and it is still giving a exact output. that is why i am asking that if it works correct without putting NULL character or NULL value then why don’t we skip NULL? we should not add NULL to our code if code can execute correctly without using NULL value.
The terminating zero is necessary if a character array contains a string. This allows to find the point where a string ends.
As for your example that as I think looks the following way
char line[100] = "hello\n";
then for starters the string literal has 7 characters. It is a string and includes the terminating zero. This string literal has type char[7] . You can imagine it like
char no_name[] = { 'h', 'e', 'l', 'l', 'o', '\n', '\0' };
in such cases you have to put null
otherwise okay
char b[]={'a','b','c'};
this will give some garbage also