Exforsys
+ Reply to Thread
Results 1 to 2 of 2

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 ...

  1. #1
    Adrian is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    124

    Question 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?


  2. #2
    Ralph is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    114
    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.


Latest Article

Network Security Risk Assessment and Measurement

Read More...