
- Forum
- Programming Talk
- C and C++
- Reason for Compiler Error
Reason for Compiler Error
This is a discussion on Reason for Compiler Error within the C and C++ forums, part of the Programming Talk category; Why is the compiler throwing error if I try to assign some value to the terminator of char array namely ...
-
Reason for Compiler Error
Why is the compiler throwing error if I try to assign some value to the terminator of char array namely '\0’? I want to know the reason for the error. Also let me know whether I can compare the terminator of char array namely '\0'using operator == or will it also throw error. If so why is it?
-
It is important to understand the concept of char arrays for your problem. Strings in C programming are represented as char arrays. Char array is terminated by a null character called as terminator denoted as '\0' and it has a char value 0.So only you cannot assign any value to the terminator of char array namely '\0’. Since you tried that you got compiler error. The terminator is automatically placed at the end of string by C programs and users have to allocate a space for this also taking consideration of this. As explained before since '\0' in a char array is null value no comparison of the terminator of char array namely '\0' using operator == is allowed.

Reply With Quote





