Character Arrays in C?
<p>I am a beginner in C Programming Language, I am very confused about the null character (<code>'\0'</code>) in the C Programming Language.</p>

<p>Based on the program below, the allowed character length for a line is <code>10</code> (<code>MAXLINE</code> is defined to <code>10</code>). An input like <code>Navindren</code> of length 9 occupies array indices <code>0</code> to <code>8</code>, whenever a new line character is reached it is added to the index <code>9</code> and <code>i</code> is incremented by <code>1</code>. <code>i</code> is <code>10</code> now and <code>s[10]</code> is assigned with the <code>'\0'</code>, <code>s[10] = '\0'</code>.</p>

<p>Here is the confusion, how is this possible since the array is only allocated space from the index <code>0</code>- <code>9</code> ? I tried referring to many online resources but the explanations are not sufficient. </p>

<p>Main Function:</p>

<pre><code>#include&lt;stdio.h&gt;
#define MAXLINE 10

int getline(char line[], int maxline);
void copy(char to[], char from[]);

main() {
    int len;                /*current line length*/
    int max;                /*maximum length seen so far*/
    char line[MAXLINE];     /*current input line*/
    char longest[MAXLINE];  /*longest line saved here*/

    max = 0;
    while ((len = getline(line, MAXLINE)) &gt; 0) {
        printf("%d\n", len);
        if (len &gt; max) {
            max = len;
            copy(longest, line);
        }
    }

    if (max &gt; 0) /* there was a line */ {
        printf("%s", longest);
    } else {
        printf("No Lines Detected\n");
    }

    return 0;
}
</code></pre>

<p>Getline Function:</p>

<pre><code>int getline(char s[], int lim) {
    int c;
    int i;

    for (i = 0; i &lt; MAXLINE - 1 &amp;&amp; (c = getchar()) != EOF &amp;&amp; c != '\n'; i++) {
            s[i] = c;
    }

    if (c == '\n') {
        s[i] = '\n';
        ++i;
    }

    s[i] = '\0';
    return i;
}
</code></pre>

<p>Copy function:</p>

<pre><code>/*copy: copy `from` into `to`; assume to is big enough*/
void copy(char to[], char from[]) {
    int i;
    i = 0;

    while ((to[i] = from[i]) != '\0') {
        ++i;
    }
}
</code></pre>